58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"ginDemo/config"
|
||
|
"ginDemo/core"
|
||
|
"ginDemo/initialize"
|
||
|
admRoute "ginDemo/route/admin"
|
||
|
"gitee.ltd/lxh/logger"
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"golang.org/x/sync/errgroup"
|
||
|
"net/http"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
var g errgroup.Group
|
||
|
|
||
|
// 系统初始化
|
||
|
func init() {
|
||
|
initialize.InitSystem() // 初始化系统配置
|
||
|
}
|
||
|
|
||
|
// 启动入口
|
||
|
func main() {
|
||
|
// 强制日志颜色化
|
||
|
gin.ForceConsoleColor()
|
||
|
// 定义启动入口
|
||
|
adm := &http.Server{
|
||
|
Addr: fmt.Sprintf(":%d", config.Scd.Admin.Port),
|
||
|
Handler: admin(),
|
||
|
ReadTimeout: 5 * time.Second,
|
||
|
WriteTimeout: 1 * time.Minute,
|
||
|
}
|
||
|
|
||
|
// 启动项目
|
||
|
g.Go(func() error {
|
||
|
return adm.ListenAndServe()
|
||
|
})
|
||
|
if err := g.Wait(); err != nil {
|
||
|
logger.Say.Panicf("启动失败,错误信息:%s", err.Error())
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 生成Admin服务
|
||
|
func admin() http.Handler {
|
||
|
app := gin.New()
|
||
|
app.Use(gin.Recovery())
|
||
|
// 开启自定义请求方式不允许处理函数
|
||
|
app.HandleMethodNotAllowed = true
|
||
|
// 处理请求方式不对
|
||
|
app.NoMethod(core.NoMethodHandler())
|
||
|
// 404返回数据
|
||
|
app.NoRoute(core.NoRouteHandler())
|
||
|
// 初始化路由
|
||
|
admRoute.InitRoute(app.Group(config.Scd.Admin.Prefix))
|
||
|
return app
|
||
|
}
|