add log convenience function
This commit is contained in:
parent
81aa0b651e
commit
f729160209
2 changed files with 10 additions and 3 deletions
|
|
@ -11,7 +11,6 @@ import (
|
|||
validation "github.com/go-ozzo/ozzo-validation"
|
||||
|
||||
"github.com/dhax/go-base/auth"
|
||||
"github.com/dhax/go-base/logging"
|
||||
"github.com/dhax/go-base/models"
|
||||
)
|
||||
|
||||
|
|
@ -54,11 +53,11 @@ func (rs *AccountResource) router() *chi.Mux {
|
|||
func (rs *AccountResource) accountCtx(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
claims := auth.ClaimsFromCtx(r.Context())
|
||||
logging.GetLogEntry(r).WithField("account_id", claims.ID)
|
||||
log(r).WithField("account_id", claims.ID)
|
||||
account, err := rs.Store.Get(claims.ID)
|
||||
if err != nil {
|
||||
// account deleted while access token still valid
|
||||
logging.GetLogEntry(r).WithField("account", claims.Sub).Warn(err)
|
||||
log(r).WithField("account", claims.Sub).Warn(err)
|
||||
render.Render(w, r, ErrNotFound)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/go-pg/pg"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/dhax/go-base/database"
|
||||
"github.com/dhax/go-base/logging"
|
||||
)
|
||||
|
||||
type ctxKey int
|
||||
|
|
@ -37,3 +41,7 @@ func (a *API) Router() *chi.Mux {
|
|||
|
||||
return r
|
||||
}
|
||||
|
||||
func log(r *http.Request) logrus.FieldLogger {
|
||||
return logging.GetLogEntry(r)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue