generated from Fs02/go-todo-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
36 lines (30 loc) · 895 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
package api
import (
"github.com/ddanurwenda/relecho/api/handler"
"github.com/ddanurwenda/relecho/scores"
"github.com/ddanurwenda/relecho/todos"
"github.com/go-chi/chi"
chimid "github.com/go-chi/chi/middleware"
"github.com/go-rel/rel"
"github.com/goware/cors"
)
// NewMux api.
func NewMux(repository rel.Repository) *chi.Mux {
var (
mux = chi.NewMux()
scores = scores.New(repository)
todos = todos.New(repository, scores)
healthzHandler = handler.NewHealthz()
todosHandler = handler.NewTodos(repository, todos)
scoreHandler = handler.NewScore(repository)
)
healthzHandler.Add("database", repository)
mux.Use(chimid.RequestID)
mux.Use(chimid.RealIP)
mux.Use(chimid.Recoverer)
mux.Use(cors.AllowAll().Handler)
mux.Mount("/healthz", healthzHandler)
mux.Mount("/todos", todosHandler)
mux.Mount("/score", scoreHandler)
return mux
}