/
router.go
40 lines (29 loc) · 956 Bytes
/
router.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
package handler
import (
"github.com/faelp22/tcs_curso/stoq/pkg/service"
"github.com/gorilla/mux"
"github.com/urfave/negroni"
)
func RegisterAPIHandlers(r *mux.Router, n *negroni.Negroni, service service.ProdutoServiceInterface) {
api := r.PathPrefix("/api/v1").Subrouter()
n.Use(applicationJSON())
n.Use(isAuth())
api.Handle("/user/login", n.With(
negroni.Wrap(authLogin()),
)).Methods("POST", "OPTIONS")
api.Handle("/products", n.With(
negroni.Wrap(getAllProduct(service)),
)).Methods("GET", "OPTIONS")
api.Handle("/product/{id}", n.With(
negroni.Wrap(getProduct(service)),
)).Methods("GET", "OPTIONS")
api.Handle("/product", n.With(
negroni.Wrap(createProduct(service)),
)).Methods("POST", "OPTIONS")
api.Handle("/product/{id}", n.With(
negroni.Wrap(updateProduct(service)),
)).Methods("PUT", "OPTIONS")
api.Handle("/product/{id}", n.With(
negroni.Wrap(deleteProduct(service)),
)).Methods("DELETE", "OPTIONS")
}