-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
50 lines (35 loc) · 1.05 KB
/
user.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package api
import (
"context"
"net/http"
"github.com/go-chi/jwtauth"
"github.com/pkg/errors"
"github.com/smarthut/smarthut/model"
)
func (api *API) userCtx(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Get JWT token from context
_, claims, err := jwtauth.FromContext(r.Context())
if err != nil {
handleError(err, w, r)
return
}
user := new(model.User)
if err := api.db.One("Username", claims["sub"], &user); err != nil {
handleError(errors.Wrapf(err, "unable to find user with name %s", claims["sub"]), w, r)
return
}
ctx := context.WithValue(r.Context(), userKey, user)
next.ServeHTTP(w, r.WithContext(ctx))
})
}
func (api *API) listUsers(w http.ResponseWriter, r *http.Request) {
}
func (api *API) createUser(w http.ResponseWriter, r *http.Request) {
}
func (api *API) getUser(w http.ResponseWriter, r *http.Request) {
}
func (api *API) updateUser(w http.ResponseWriter, r *http.Request) {
}
func (api *API) deleteUser(w http.ResponseWriter, r *http.Request) {
}