-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathroutes.go
More file actions
31 lines (26 loc) · 840 Bytes
/
routes.go
File metadata and controls
31 lines (26 loc) · 840 Bytes
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
// Package server provides an HTTP server implementation serving the ToDo app.
package server
import (
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
)
// initializeRouter initializes the chi.Router instance, mounts all supported
// routes and registers the REST controller's methods as handler functions.
//
// Also, initializeRouter registers any middleware to be used by the router.
func (s *Server) initializeRouter() {
s.router = chi.NewRouter()
s.router.Use(
middleware.Logger,
middleware.RedirectSlashes,
)
s.router.Route("/todos", func(r chi.Router) {
r.Post("/", s.controller.CreateToDo())
r.Get("/", s.controller.GetToDos())
r.Route("/{id}", func(r chi.Router) {
r.Get("/", s.controller.GetToDo())
r.Put("/", s.controller.UpdateToDo())
r.Delete("/", s.controller.DeleteToDo())
})
})
}