-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrouter.go
31 lines (23 loc) · 982 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
package main
import (
"os"
"./controllers"
"./middlewares"
"github.com/gorilla/mux"
)
func routerConfig() *mux.Router {
pathPrefix := os.Getenv("API_PATH_PREFIX")
router := mux.NewRouter().StrictSlash(true).PathPrefix(pathPrefix).Subrouter()
router.Use(middlewares.RequestLogger)
// Index Request
router.HandleFunc("/", controllers.IndexHandlerGET).Methods("GET")
// Users Request
router.HandleFunc("/users/register", controllers.UsersRegisterHandler).Methods("POST")
router.HandleFunc("/users/login", controllers.UsersLogin).Methods("POST")
// Posts Request
router.HandleFunc("/posts", controllers.ListPostHandler).Methods("GET")
router.HandleFunc("/posts", middlewares.JWTMiddleware(controllers.CreatePostHandler)).Methods("POST")
router.HandleFunc("/posts", middlewares.JWTMiddleware(controllers.DeletePostHandler)).Methods("DELETE")
router.HandleFunc("/posts", middlewares.JWTMiddleware(controllers.UpdatePostHandler)).Methods("PATCH")
return router
}