feat:完善项目
This commit is contained in:
@ -31,6 +31,15 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (this *Router) registerWeb() {
|
||||
this.handler.LoadHTMLGlob("dist/*.html") // 添加入口index.html
|
||||
this.handler.LoadHTMLFiles("dist/*") // 添加资源路径
|
||||
this.handler.Static("/js", "dist/js")
|
||||
this.handler.Static("/css", "dist/css")
|
||||
this.handler.Static("/assets", "dist/assets")
|
||||
this.handler.StaticFile("/", "dist/index.html") //前端接口
|
||||
}
|
||||
|
||||
func (this *Router) registerAPI() {
|
||||
apiPrefix := "/api"
|
||||
g := this.handler.Group(apiPrefix)
|
||||
@ -54,6 +63,14 @@ func (this *Router) registerAPI() {
|
||||
v1.GET("/captcha", new(api.Captcha).Captcha)
|
||||
// Upload 上传接口管理
|
||||
v1.POST("/upload", new(api.Upload).Upload)
|
||||
// Dashboard 验证码接口管理
|
||||
dashboardV1 := v1.Group("/dashboard")
|
||||
{
|
||||
_api := new(api.Dashboard)
|
||||
dashboardV1.GET("/", _api.Index)
|
||||
dashboardV1.POST("/repair", _api.Repair)
|
||||
dashboardV1.GET("/score", _api.Score)
|
||||
}
|
||||
// Account 接口管理
|
||||
accountV1 := v1.Group("/account")
|
||||
{
|
||||
@ -197,22 +214,24 @@ func (this *Router) Init() *gin.Engine {
|
||||
app.NoMethod(NoMethodHandler())
|
||||
app.Use(LoggerHandle("log/gin.log", 3))
|
||||
app.Use(TimeoutHandle(time.Second * 30))
|
||||
app.Use(RecoveryHandler())
|
||||
|
||||
if config.IsDebug() {
|
||||
gin.DefaultWriter = io.MultiWriter(os.Stdout)
|
||||
app.StaticFS("/api-docs", http.Dir("./doc"))
|
||||
} else {
|
||||
app.Use(RecoveryHandler())
|
||||
}
|
||||
if this.RateLimitConfig != nil {
|
||||
if this.RateLimitConfig.IsRate {
|
||||
rate.NewIPRateLimiter()(this.RateLimitConfig.Limit, this.RateLimitConfig.Capacity)
|
||||
app.Use(rate.RequestIPRateLimiter()(this.RateLimitConfig.Limit, this.RateLimitConfig.Capacity))
|
||||
}
|
||||
}
|
||||
if config.IsDebug() {
|
||||
gin.DefaultWriter = io.MultiWriter(os.Stdout)
|
||||
app.StaticFS("/api-docs", http.Dir("./doc"))
|
||||
}
|
||||
app.StaticFS("/upload", http.Dir("./upload"))
|
||||
app.MaxMultipartMemory = 4 << 20
|
||||
this.handler = app
|
||||
// 注册路由
|
||||
this.registerWeb()
|
||||
this.registerAPI()
|
||||
|
||||
return app
|
||||
|
Reference in New Issue
Block a user