online-order/main.go

62 lines
1.3 KiB
Go
Raw Normal View History

2023-10-27 22:12:56 +00:00
package main
2023-10-27 09:51:58 +00:00
import (
"context"
"log"
2023-10-27 22:12:56 +00:00
handler_products "online-order/api/handlers/products"
2023-10-27 09:51:58 +00:00
"github.com/gin-gonic/gin"
_ "github.com/go-sql-driver/mysql"
logger "github.com/rs/zerolog/log"
"online-order/configs"
"online-order/ent/migrate"
"online-order/entity"
)
// To load .env file
func init() {
configs.Initialize()
}
func main() {
logger.Info().Msg("Server starting ...")
conf := configs.LoadConfigEnv()
// Start by connecting to database
db := configs.NewDBConnection()
defer db.Close()
// Run the automatic migration tool to create all schema resources.
ctx := context.Background()
err := db.Schema.Create(
ctx,
migrate.WithDropIndex(true),
migrate.WithDropColumn(true),
)
if err != nil {
log.Fatalf("failed creating schema resources: %v", err)
}
app := gin.Default()
api_v1 := app.Group("api/v1")
api_restricted := app.Group("api/v1/in")
router_base := &entity.RouterBase{
Database: db,
OpenApp: api_v1,
}
router := &entity.Routers{
RouterBase: *router_base,
RestrictedApp: api_restricted,
}
2023-10-27 22:12:56 +00:00
//middlewareController := middlewares.NewMiddlewareRouters(router)
//api_restricted.Use(middlewareController.JwAuthtMiddleware())
2023-10-27 09:51:58 +00:00
2023-10-27 22:12:56 +00:00
handler_products.NewProductRouters(router)
2023-10-27 09:51:58 +00:00
logger.Info().Msg("Server ready to go ...")
app.Run(conf.ServerPort)
}