package main

import (
	"fmt"

	"bsm/full/module/base/fts/internal/config"
	"bsm/full/module/base/fts/internal/impl"
	"bsm/full/module/base/fts/internal/routers"
	"git.apinb.com/bsm-sdk/core/infra"
	"git.apinb.com/bsm-sdk/core/middleware"
	"github.com/gin-gonic/gin"
)

var (
	ServiceKey = "fts"
)

func Run() {
	config.New(ServiceKey)
	impl.NewImpl()

	// 初始化Gin引擎
	app := gin.Default()

	// gin 中间件
	app.Use(middleware.Cors())
	app.Use(gin.Recovery())
	middleware.Mode(app)

	if config.Spec.OnMicroService {
		// register service
		infra.Service.Register(impl.EtcdService, ServiceKey, config.Spec.Port)
	}

	// register health check
	app.HEAD("/", infra.Health)

	// register routers
	routers.Register(ServiceKey, app)

	// start
	err := app.Run(fmt.Sprintf(":%s", config.Spec.Port))
	if err != nil {
		panic(err)
	}
}

func main() {
	Run()
}
