Impl swag and auth switch

This commit is contained in:
若海
2023-12-29 21:28:18 +08:00
parent 21f63ee545
commit 524faae9cf
12 changed files with 148 additions and 54 deletions
+12 -2
View File
@@ -8,7 +8,7 @@ import (
"wechat-rest/args"
)
func AuthGuard(c *gin.Context) {
func ApiGuard(c *gin.Context) {
token := ""
@@ -19,9 +19,19 @@ func AuthGuard(c *gin.Context) {
}
if token != args.Httpd.Token {
c.Set("Error", gin.H{"Code": 401, "Message": "未授权的操作"})
c.Set("Error", gin.H{"Code": 401, "Message": "操作未授权"})
c.Set("ExitCode", 401)
c.Abort()
}
}
func SwagGuard(c *gin.Context) {
if !args.Httpd.Swag && strings.HasPrefix(c.Request.URL.Path, "/swag") {
c.Set("Error", gin.H{"Code": 403, "Message": "功能已禁用"})
c.Set("ExitCode", 403)
c.Abort()
}
}