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