-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
53 lines (40 loc) · 897 Bytes
/
api.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
51
52
53
// Package app ties together application resources and handlers.
package app
import (
"net/http"
"github.com/go-chi/chi"
"github.com/sirupsen/logrus"
"github.com/dhax/go-base/logging"
)
type ctxKey int
const (
ctxAccount ctxKey = iota
ctxProfile
)
// API provides application resources and handlers.
type API struct {
Links *LinksResource
}
// NewAPI configures and returns application API.
func NewAPI() (*API, error) {
links := NewLinksResource()
api := &API{
Links: links,
}
return api, nil
}
// Router provides application routes.
func (a *API) Router() *chi.Mux {
r := chi.NewRouter()
// r.Group(func(r chi.Router) {
// r.Use(jwt.Authenticator)
// r.Mount("/profile", a.Profile.router())
// })
r.Group(func(r chi.Router) {
r.Mount("/links", a.Links.router())
})
return r
}
func log(r *http.Request) logrus.FieldLogger {
return logging.GetLogEntry(r)
}