package main import ( "context" "github.com/gin-gonic/gin" _ "github.com/go-sql-driver/mysql" logger "github.com/rs/zerolog/log" "log" "online-order/api" "online-order/cmd" "online-order/configs" "online-order/ent/migrate" ) // To load .env file func init() { configs.Initialize() } // @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/ 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) } cmd.Run() app := gin.Default() api.Router(app, db) app.Run(":" + conf.ServerPort) }