GoDoc and some typos...

This commit is contained in:
dhax 2017-10-22 21:56:36 +02:00
parent 9f37579562
commit 543b39f822
15 changed files with 37 additions and 19 deletions

View file

@ -1,5 +1,6 @@
# Go Restful API Boilerplate
## Go Restful API Boilerplate
[![GoDoc Badge]][GoDoc] [![GoReportCard Badge]][GoReportCard]
Easily extendible RESTful API boilerplate aiming to follow idiomatic go and best practice.
@ -75,3 +76,8 @@ EMAIL_FROM_NAME | string || from name used in sending emails
### Contributing
Any feedback and pull requests are welcome and highly appreciated. Please open an issue first if you intend to send in a larger pull request or want to add additional features.
[GoDoc]: https://godoc.org/github.com/dhax/go-base
[GoDoc Badge]: https://godoc.org/github.com/dhax/go-base?status.svg
[GoReportCard]: https://goreportcard.com/report/github.com/dhax/go-base
[GoReportCard Badge]: https://goreportcard.com/badge/github.com/dhax/go-base

View file

@ -27,7 +27,7 @@ type AccountStore interface {
Delete(*auth.Account) error
}
// AccountResource implements account managment handler.
// AccountResource implements account management handler.
type AccountResource struct {
Store AccountStore
}

View file

@ -1,3 +1,4 @@
// Package admin ties together administration resources and handlers.
package admin
import (

View file

@ -1,3 +1,4 @@
// Package api configures an http server for administration and application resources.
package api
import (
@ -19,8 +20,8 @@ import (
"github.com/go-chi/render"
)
// NewAPI configures application resources and routes.
func NewAPI() (*chi.Mux, error) {
// New configures application resources and routes.
func New() (*chi.Mux, error) {
logger := logging.NewLogger()
db, err := database.DBConn()

View file

@ -22,7 +22,7 @@ type AccountStore interface {
DeleteToken(*auth.Token) error
}
// AccountResource implements account managment handler.
// AccountResource implements account management handler.
type AccountResource struct {
Store AccountStore
}
@ -64,7 +64,7 @@ func (rs *AccountResource) accountCtx(next http.Handler) http.Handler {
type accountRequest struct {
*auth.Account
// override protected data here, although not really neccessary here
// override protected data here, although not really necessary here
// as we limit updated database columns in store as well
ProtectedID int `json:"id"`
ProtectedActive bool `json:"active"`

View file

@ -1,3 +1,4 @@
// Package app ties together application resources and handlers.
package app
import (

View file

@ -19,7 +19,7 @@ type Server struct {
// NewServer creates and configures an APIServer serving all application routes.
func NewServer() (*Server, error) {
log.Println("configuring server...")
api, err := NewAPI()
api, err := New()
if err != nil {
return nil, err
}

View file

@ -1,3 +1,5 @@
// Package auth provides JSON Web Token (JWT) authentication and authorization middleware.
// It implements a passwordless authentication flow by sending login tokens vie email which are then exchanged for JWT access and refresh tokens.
package auth
import (
@ -59,7 +61,7 @@ func NewResource(store Storer, mailer Mailer) (*Resource, error) {
return resource, nil
}
// Router provides neccessary routes for passwordless authentication flow.
// Router provides necessary routes for passwordless authentication flow.
func (rs *Resource) Router() *chi.Mux {
r := chi.NewRouter()
r.Use(render.SetContentType(render.ContentTypeJSON))

View file

@ -241,14 +241,16 @@ func TestAuthResource_refresh(t *testing.T) {
if tc.status == http.StatusUnauthorized && authstore.SaveRefreshTokenInvoked {
t.Errorf("SaveRefreshToken invoked for status %d", tc.status)
}
if tc.status == http.StatusOK && !authstore.GetByRefreshTokenInvoked {
t.Errorf("GetRefreshToken not invoked")
}
if tc.status == http.StatusOK && !authstore.SaveRefreshTokenInvoked {
t.Errorf("SaveRefreshToken not invoked")
}
if tc.status == http.StatusOK && authstore.DeleteRefreshTokenInvoked {
t.Errorf("DeleteRefreshToken should not be invoked")
if tc.status == http.StatusOK {
if !authstore.GetByRefreshTokenInvoked {
t.Errorf("GetRefreshToken not invoked")
}
if !authstore.SaveRefreshTokenInvoked {
t.Errorf("SaveRefreshToken not invoked")
}
if authstore.DeleteRefreshTokenInvoked {
t.Errorf("DeleteRefreshToken should not be invoked")
}
}
authstore.GetByRefreshTokenInvoked = false
authstore.SaveRefreshTokenInvoked = false

View file

@ -61,7 +61,7 @@ func init() {
}
func genRoutesDoc() {
api, _ := api.NewAPI()
api, _ := api.New()
fmt.Print("generating routes markdown file: ")
md := docgen.MarkdownRoutesDoc(api, docgen.MarkdownOpts{
ProjectPath: "github.com/dhax/go-base",

View file

@ -1,3 +1,4 @@
// Package migrate implements postgres migrations.
package migrate
import (

View file

@ -1,3 +1,4 @@
// Package database implements postgres connection and queries.
package database
import (

View file

@ -1,3 +1,4 @@
// Package email provides email sending functionality.
package email
import (

View file

@ -1,3 +1,4 @@
// Package logging provides structured logging with logrus.
package logging
import (
@ -93,7 +94,7 @@ func (l *StructuredLoggerEntry) Write(status, bytes int, elapsed time.Duration)
l.Logger = l.Logger.WithFields(logrus.Fields{
"resp_status": status,
"resp_bytes_length": bytes,
"resp_elasped_ms": float64(elapsed.Nanoseconds()) / 1000000.0,
"resp_elapsed_ms": float64(elapsed.Nanoseconds()) / 1000000.0,
})
l.Logger.Infoln("request complete")

View file

@ -1,3 +1,4 @@
// Package models contains application specific entities.
package models
import (