package main

import (
	"dsbqj-admin/app/router"
	"dsbqj-admin/pkg/logger"
	"dsbqj-admin/pkg/validator"
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/joho/godotenv"
	"log"
	"net/http"
	"os"
	"time"
)

// @title           后端接口API文档
// @version         1.0
// @description     这里展示所有当前web端API接口信息

// @host      localhost:30101
// @BasePath  /web/v1

// @securityDefinitions.apikey cxy_token
// @name __CXY_TOKEN_
// @in header
// @securityDefinitions.apikey cxy_uid
// @name __CXY_UID_
// @in header

func main() {
	err := godotenv.Load()
	if err != nil {
		log.Fatal("Error loading .env file")
		return
	}
	validator.Init()
	logger.Init("")
	//cache.Redis()
	//oss.Init()
	//sms.Init()

	// 连接数据库
	//mysql.Database(os.Getenv("MYSQL_DSN"))
	//mongo.Database(os.Getenv("MONGO_DSN"))

	// 启动任务
	//task.Init().Run()

	if os.Getenv("GIN_MODE") == "release" {
		gin.SetMode(gin.ReleaseMode)
	}

	// 装载路由
	routersInit := router.NewRouter()
	readTimeout := 60 * time.Second
	writeTimeout := 200 * time.Second
	endPoint := fmt.Sprintf(":%s", os.Getenv("LISTEN_PORT"))
	maxHeaderBytes := 1 << 20

	server := &http.Server{
		Addr:           endPoint,
		Handler:        routersInit,
		ReadTimeout:    readTimeout,
		WriteTimeout:   writeTimeout,
		MaxHeaderBytes: maxHeaderBytes,
	}

	logger.Info("start http version listening %s", endPoint)
	err = server.ListenAndServe()
	fmt.Println(err)
}
