12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package main
- import (
- "fmt"
- "github.com/gin-gonic/gin"
- "github.com/sirupsen/logrus"
- "lcfns/eventServer"
- "lcfns/gatewayServer"
- "lcfns/global"
- "lcfns/initialize"
- "lcfns/service/system"
- "net/http"
- "time"
- )
- func main() {
- initialize.InitLogrus()
- go eventServer.StartEventServer() //摄像头事件监听服务端
- go gatewayServer.GatewayServe() //网关服务端
- 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,
- }
- }
|