package main import ( "fmt" "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" "lc-fangdaosha/global" "lc-fangdaosha/initialize" "lc-fangdaosha/service/system" "net/http" "os" "time" ) func main() { logrus.SetLevel(logrus.DebugLevel) logrus.SetOutput(os.Stdout) logrus.SetReportCaller(true) initialize.OtherInit() //初始化缓存 //initialize.Redis() global.Db = initialize.Gorm() //初始化数据库orm if global.Db != nil { // 程序结束前关闭数据库链接 db, _ := global.Db.DB() defer db.Close() } if global.Config.System.UseMultipoint || global.Config.System.UseRedis { // 初始化redis服务 initialize.Redis() } // 从db加载jwt黑名单数据 if global.Db != nil { system.LoadAll() } Router := initialize.Routers() address := fmt.Sprintf(":%d", global.Config.System.Addr) s := initServer(address, Router) logrus.Error(s.ListenAndServe().Error()) } type server interface { ListenAndServe() error } func initServer(address string, router *gin.Engine) server { return &http.Server{ Addr: address, Handler: router, ReadTimeout: 20 * time.Second, WriteTimeout: 20 * time.Second, MaxHeaderBytes: 1 << 20, } }