-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
35 lines (27 loc) · 874 Bytes
/
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
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"server2/handlers"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
)
func main() {
router := gin.Default()
store := cookie.NewStore([]byte("something_new_secret"))
router.Use(sessions.Sessions("recipes_api", store))
router.GET("/recipes", handlers.GetAllRecipes)
router.POST("/signin", handlers.SignInHandler)
router.POST("/refresh", handlers.RefreshHandler)
authorized := router.Group("/")
authorized.Use(handlers.AuthMiddleware())
{
authorized.GET("/", handlers.RootHandler)
authorized.GET("/recipes/:Id", handlers.GetRecipeById)
authorized.DELETE("/recipes/:Id", handlers.DeleteRecipe)
authorized.PUT("/recipes/:Id", handlers.UpdateRecipe)
authorized.POST("/recipes", handlers.CreateRecipe)
}
fmt.Println("server is running on port 8080")
router.Run()
}