package main

import (
	"Crimson-Gatekeeper/internal/common"
	"Crimson-Gatekeeper/internal/middle"
	"Crimson-Gatekeeper/internal/query"
	"Crimson-Gatekeeper/internal/user"
	"fmt"

	"github.com/gin-gonic/gin"
)

func main() {
	app, clean := launchApplication()
	defer clean()
	err := app.Run(":3333")
	if err != nil {
		fmt.Println("应用启动失败")
		panic(err)
	}
}

func launchApplication() (*gin.Engine, func() error) {
	db, clean := common.GetDataBaseClient()
	q := query.Use(db)
	app := gin.Default()
	app.Use(middle.ResponsePackageMiddle)
	user.New(q).RegisterRoute(app)
	return app, clean
}
