package main

import (
	"fmt"
	"net/http"

	"Crimson-Gatekeeper/internal/common"
	"Crimson-Gatekeeper/internal/user"

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

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

func launchApplication() (*gin.Engine, func() error) {
	client, close := common.GetDataBaseClient()
	app := gin.Default()
	app.GET("/test", func(ctx *gin.Context) {
		fmt.Println(ctx.Request.URL.Path)
		ctx.JSON(http.StatusOK, gin.H{
			"message": "success",
		})
	})
	user.New(client).RegisterRoute(app)
	return app, close
}
