-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.go
48 lines (38 loc) · 933 Bytes
/
routes.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
// Package app ties together application resources and handlers.
package app
import (
"github.com/go-chi/chi"
"github.com/go-pg/pg"
"github.com/sirupsen/logrus"
"net/http"
"github.com/dashwav/nano-api/api/app/emoji"
"github.com/dashwav/nano-api/database"
"github.com/dashwav/nano-api/logging"
)
type ctxKey int
const (
ctxAccount ctxKey = iota
ctxProfile
)
// API provides application resources and handlers.
type API struct {
Emoji *emoji.EmojiResource
}
// NewAPI configures and returns application API.
func NewAPI(db *pg.DB) (*API, error) {
userStore := database.NewEmojiStore(db)
emojiApi := emoji.NewEmojiResource(userStore)
api := &API{
Emoji: emojiApi,
}
return api, nil
}
// Router provides application routes.
func (a *API) Router() *chi.Mux {
r := chi.NewRouter()
r.Mount("/emojis", a.Emoji.Router())
return r
}
func log(r *http.Request) logrus.FieldLogger {
return logging.GetLogEntry(r)
}