-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (36 loc) · 1.05 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
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
"github.com/yaswanthsaivendra/prod_mang/database"
"github.com/yaswanthsaivendra/prod_mang/handlers"
"github.com/yaswanthsaivendra/prod_mang/middleware"
"github.com/yaswanthsaivendra/prod_mang/model"
)
func main() {
loadDB()
serveApplication()
}
func Migrate(db *gorm.DB) {
database.Database.AutoMigrate(&model.User{})
database.Database.AutoMigrate(&model.Product{})
database.Database.AutoMigrate(&model.Image{})
}
func loadDB() {
db := database.InitDB()
Migrate(db)
}
func serveApplication() {
router := gin.Default()
publicRoutes := router.Group("/auth")
publicRoutes.POST("/register", handlers.Register)
publicRoutes.POST("/login", handlers.Login)
protectedRoutes := router.Group("/api")
protectedRoutes.Use(middleware.JWTAuthMiddleware())
router.MaxMultipartMemory = 8 << 20
protectedRoutes.POST("/product", handlers.HandleProductUpload)
protectedRoutes.GET("/product", handlers.GetAllProductsOfUser)
router.Run(":8000")
fmt.Println("server running on port 8000")
}