online-order/main.go

63 lines
1.4 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"
"github.com/gin-gonic/gin"
_ "github.com/go-sql-driver/mysql"
logger "github.com/rs/zerolog/log"
2023-10-29 23:33:40 +00:00
"log"
2023-10-31 16:31:06 +00:00
"online-order/api"
2023-10-27 09:51:58 +00:00
"online-order/configs"
"online-order/ent/migrate"
)
// To load .env file
func init() {
configs.Initialize()
}
2023-10-29 23:33:40 +00:00
// @title Swagger Example API
// @version 1.0
// @description This is a sample server celler server.
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email support@swagger.io
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host localhost:9000
// @BasePath /api/v1
// @securityDefinitions.basic BasicAuth
// @externalDocs.description OpenAPI
// @externalDocs.url https://swagger.io/resources/open-api/
2023-10-27 09:51:58 +00:00
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()
2023-10-29 23:33:40 +00:00
2023-10-31 16:31:06 +00:00
api.Router(app, db)
2023-10-29 23:33:40 +00:00
app.Run(":" + conf.ServerPort)
2023-10-27 09:51:58 +00:00
}