-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (48 loc) · 1.51 KB
/
main.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
51
52
53
54
55
56
57
58
59
60
package main
import (
"net/http"
"github.com/JadlionHD/crud-gin-go/api/server/middleware"
"github.com/JadlionHD/crud-gin-go/api/server/routes"
"github.com/JadlionHD/crud-gin-go/internal/database"
"github.com/gin-gonic/gin"
)
func init() {
database.InitDatabase()
}
func main() {
router := gin.Default()
router.GET("/", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "Hello world",
})
})
router.POST("/login", routes.LoginHandler)
// r.NoRoute(handle.MiddlewareFunc(), func(c *gin.Context) {
// claims := jwt.ExtractClaims(c)
// log.Printf("NoRoute claims: %#v\n", claims)
// c.JSON(404, gin.H{"code": "PAGE_NOT_FOUND", "message": "Page not found"})
// })
auth := router.Group("/auth", middleware.AuthMiddleware())
auth.GET("/hello", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "HELLO WORLD",
})
})
// auth := r.Group("/auth", handle.MiddlewareFunc())
// auth.GET("/refresh_token", handle.RefreshHandler)
// auth.GET("/hello", func(c *gin.Context) {
// claims := jwt.ExtractClaims(c)
// user, _ := c.Get(middleware.IdentityKey)
// c.JSON(http.StatusOK, gin.H{
// "userID": claims[middleware.IdentityKey],
// "userName": user.(*types.User).UserName,
// "text": "Hello World.",
// })
// })
api := router.Group("/api", middleware.AuthMiddleware())
api.GET("/posts/:id", routes.GetPost)
api.POST("/posts", routes.CreatePost)
api.DELETE("/posts/:id", routes.DeletePost)
api.PUT("/posts/:id", routes.UpdatePost)
router.Run("localhost:8080")
}