| 123456789101112131415161718192021222324252627282930313233343536373839 |
- package core
- import (
- "fmt"
- "mtp20access/global"
- "mtp20access/initialize"
- "net/http"
- "time"
- "github.com/gin-gonic/gin"
- "go.uber.org/zap"
- )
- type server interface {
- ListenAndServe() error
- }
- func RunServer() {
- // 初始化redis服务
- initialize.Redis()
- // 从redis加载jwt数据
- // 启动服务
- Router := initialize.Routers()
- address := fmt.Sprintf(":%d", global.M2A_CONFIG.System.Addr)
- s := initServer(address, Router)
- global.M2A_LOG.Info("server run success on ", zap.String("address", address))
- global.M2A_LOG.Error(s.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,
- }
- }
|