preorder/main.go

46 lines
826 B
Go
Raw Normal View History

2024-06-18 04:37:32 +00:00
package main
import (
2024-06-20 02:49:55 +00:00
"gorm.io/gorm"
2024-06-18 04:37:32 +00:00
"net/http"
2024-06-20 02:49:55 +00:00
"preorder/authors"
"preorder/config"
"preorder/formats"
"preorder/orders"
"preorder/users"
2024-06-18 04:37:32 +00:00
"github.com/gin-gonic/gin"
)
func SetupRouter() *gin.Engine {
router := gin.Default()
router.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{"message": "pong"})
})
2024-06-20 02:49:55 +00:00
router = authors.ApplyAuthorRouter(router)
router = formats.ApplyFormatRouter(router)
router = orders.ApplyOrderRouter(router)
2024-06-18 04:37:32 +00:00
return router
}
2024-06-20 02:49:55 +00:00
func Migrate(db *gorm.DB) {
_ = db.AutoMigrate(&authors.Author{})
_ = db.AutoMigrate(&formats.Format{})
_ = db.AutoMigrate(&orders.Order{})
_ = db.AutoMigrate(&users.User{})
}
2024-06-18 04:37:32 +00:00
func main() {
router := SetupRouter()
2024-06-20 02:49:55 +00:00
config.ConnectDatabase()
Migrate(config.DB)
2024-06-18 04:37:32 +00:00
s := &http.Server{
Addr: ":8123",
Handler: router,
}
s.ListenAndServe()
}