/
routes.go
37 lines (33 loc) · 1.04 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
package api
import (
"github.com/gorilla/mux"
"github.com/urfave/negroni"
)
//Setup the routes and middlware
func setRoutes() (n *negroni.Negroni) {
router := mux.NewRouter()
router.HandleFunc("/", rootHandler)
router.HandleFunc("/locations", locationGetHandler).
Methods("GET")
//Unsure whether to use POST or PUT here.
//Using POST as it's /locations not /locations/{id}
router.HandleFunc("/locations", locationPostHandler).
Methods("POST")
router.HandleFunc("/locations/{location}", productGetHandler).
Methods("GET")
router.HandleFunc("/locations/{location}", productPostHandler).
Methods("POST")
router.HandleFunc("/recipes", recipeGetHandler).
Methods("GET")
router.HandleFunc("/recipes/{recipe}", recipeGetHandler).
Methods("GET")
router.HandleFunc("/recipes", recipePostHandler).
Methods("POST")
//Set the jwt handler which will verify the token.
//Let negroni handle this.
tokenMiddleware := verifyToken()
n = negroni.New()
n.Use(negroni.HandlerFunc(tokenMiddleware.HandlerWithNext))
n.UseHandler(router)
return n
}