-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (48 loc) · 1.4 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
61
62
63
package main
import (
"gin-gorm-go/common"
"gin-gorm-go/migration"
"gin-gorm-go/restaurant"
"gin-gorm-go/user"
"log"
"github.com/gin-gonic/gin"
)
func init() {
common.InitDB()
migration.RunMigrations()
}
func main() {
r := gin.Default()
r.LoadHTMLGlob("templates/*")
r.GET("/", func(ctx *gin.Context) {
ctx.JSON(200, gin.H{"message": "Hello World"})
})
r.GET("/template1", func(ctx *gin.Context) {
ctx.HTML(200, "template1.html", gin.H{})
})
r.GET("/template2", func(ctx *gin.Context) {
ctx.HTML(200, "template2.tmpl", gin.H{"name": "Kevin"})
})
userRoutes := r.Group("/user")
{
userRoutes.GET("/", user.GetUserAll)
userRoutes.GET("/:id", user.GetUser)
userRoutes.POST("/create", user.CreateUser)
userRoutes.PATCH("/update/:id", user.UpdateUser)
userRoutes.DELETE("/delete/:id", user.DeleteUser)
}
restaurantRoutes := r.Group("/restaurant")
{
restaurantRoutes.GET("/", restaurant.GetRestaurantAll)
restaurantRoutes.GET("/:id", restaurant.GetRestaurant)
restaurantRoutes.POST("/create", restaurant.CreateRestaurant)
restaurantRoutes.PATCH("/update/:id", restaurant.UpdateRestaurant)
restaurantRoutes.DELETE("/delete/:id", restaurant.DeleteRestaurant)
restaurantRoutes.GET("/addLike/:id", restaurant.AddLike)
restaurantRoutes.GET("/addDislike/:id", restaurant.AddDislike)
}
err := r.Run("localhost:8080")
if err != nil {
log.Fatal("Failed to start server")
}
}