package main

import (
	"DataShare/config"
	"DataShare/global"
	"DataShare/initApp"
	"DataShare/service"
	"DataShare/service/cron"
	"fmt"
	"github.com/fvbock/endless"
	"os"
	"time"
)

func init(){
	//读取配置文件
	dir,err := os.Getwd()
	if err != nil {
		fmt.Println("get dir error:"+err.Error())
	}
	err = config.ConfigParse(dir+"/config/config.yml",&global.SystemConfig)
	if err != nil {
		fmt.Println("init config file error:"+err.Error())
	}
	//初始化日志
	initApp.LoggerInit()
	initApp.RedisInit()
	initApp.ValidatorInit()
	//加载连接信息
	service.LoadDefaultDbConnect()

	cron.GetInstance().Start()
}

func main(){
	//data,err := api_proxy.GovFormatTest()
	//if err != nil {
	//	fmt.Println(err)
	//	return
	//}
	//fmt.Println(data)
	//return

	address := fmt.Sprintf(":%d", global.SystemConfig.System.Port)
	router := initApp.RoutersInit()
	server := endless.NewServer(address, router)
	server.ReadHeaderTimeout = 10 * time.Millisecond
	server.WriteTimeout = 10 * time.Second
	server.MaxHeaderBytes = 1 << 20
	global.SystemLogger.Info("项目已启动")
	global.SystemLogger.Info("swagger文档地址：http://localhost:28080/swagger/index.html")

	server.ListenAndServe()

	cron.GetInstance().Stop()

	fmt.Println("bye byte")
}
