-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.go
50 lines (39 loc) · 1.31 KB
/
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
41
42
43
44
45
46
47
48
49
50
package main
import (
"github.com/coffemanfp/beppin-server/config"
"github.com/coffemanfp/beppin-server/handlers"
"github.com/coffemanfp/beppin-server/models"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
)
func newRouter(e *echo.Echo) {
settings := config.GetSettings()
// API group
r := e.Group("/v1")
// Sign In
r.POST("/login", handlers.Login)
r.POST("/login/:provider", handlers.LoginWithProvider)
// Sign Up
r.POST("/signup", handlers.SignUp)
// Products
r.GET("/products", handlers.GetProducts)
r.GET("/products/:id", handlers.GetProduct)
// JWT Middleware
jwtConfig := middleware.JWTConfig{
Claims: &models.Claim{},
SigningKey: []byte(settings.SecretKey),
TokenLookup: "header:" + echo.HeaderAuthorization,
}
jwtMiddleware := middleware.JWTWithConfig(jwtConfig)
// Products
r.POST("/products", handlers.CreateProduct, jwtMiddleware)
r.PUT("/products/:id", handlers.UpdateProduct, jwtMiddleware)
r.DELETE("/products/:id", handlers.DeleteProduct, jwtMiddleware)
// Users
r.GET("/users", handlers.GetUsers, jwtMiddleware)
r.GET("/users/:id", handlers.GetUser, jwtMiddleware)
r.PUT("/users/:id", handlers.UpdateUser, jwtMiddleware)
r.PUT("/users/:id/avatar", handlers.UpdateAvatar, jwtMiddleware)
r.DELETE("/users/:id", handlers.DeleteUser, jwtMiddleware)
return
}