-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.go
42 lines (33 loc) · 1.13 KB
/
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
package questions
import (
"net/http"
"github.com/go-chi/chi"
"github.com/undeadops/enigma/pkg/config"
"github.com/undeadops/enigma/pkg/models"
)
// Handler - Context for Handling of Questions routes
type Handler struct {
repo models.QuestionsData
qset models.QuestionSetData
}
// NewHandler - Initialize Handler
func NewHandler(q models.QuestionsData, qs models.QuestionSetData) *Handler {
return &Handler{
repo: q,
qset: qs,
}
}
// Router - A completely separate router the questions data storage handle
func Router(h *Handler) http.Handler {
r := chi.NewRouter()
r.Use(authHandler)
r.Get("/", config.HoneycombMiddleware(h.GetResponses))
r.Get("/{id:[0-9a-f]+}", config.HoneycombMiddleware(h.GetResponseID))
r.Post("/", config.HoneycombMiddleware(h.SaveResponse))
r.Put("/{id:[0-9a-f]+}", config.HoneycombMiddleware(h.UpdateResponse))
r.Delete("/{id:[0-9a-f]+}", config.HoneycombMiddleware(h.DeleteResponse))
r.Get("/sets", config.HoneycombMiddleware(h.GetQuestionSet))
r.Post("/sets", config.HoneycombMiddleware(h.SaveQuestionSet))
r.Delete("/{id:[0-9a-f]+}", config.HoneycombMiddleware(h.DeleteQuestionSet))
return r
}