-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (34 loc) · 989 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
36
37
38
39
40
41
42
43
package main
import (
"github.com/AbdulrahmanMasoud/blog/controllers"
"github.com/AbdulrahmanMasoud/blog/database"
"github.com/AbdulrahmanMasoud/blog/middlewares"
"github.com/AbdulrahmanMasoud/blog/models"
"github.com/gin-gonic/gin"
)
func main() {
db := database.Connect()
conn := database.Connection(db)
defer conn.Close()
//db.Migrator().DropTable(&models.Blog{})
db.AutoMigrate(&models.User{}, &models.Blog{})
route := gin.Default()
route.POST("/register", controllers.Register)
route.POST("/login", controllers.Login)
route.Use(middlewares.IsAuth())
{
route.GET("/profile", controllers.Profile)
//Blog Resource
blogs := route.Group("/blogs")
{
blogs.GET("/", controllers.Index)
blogs.GET("/:id", controllers.Show)
blogs.POST("/store", controllers.Store)
blogs.PUT("/:id/update", controllers.Update)
blogs.DELETE("/:id/delete", controllers.Delete)
// By User
blogs.GET("user/:user_id", controllers.ShowByUser)
}
}
route.Run()
}