Files
x_admin/server/middleware/show.go
xiangheng 8eb583397d init
2023-11-24 16:46:30 +08:00

25 lines
687 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package middleware
import (
"strings"
"x_admin/config"
"x_admin/core/response"
"x_admin/util"
"github.com/gin-gonic/gin"
)
// ShowMode 演示模式中间件演示模式禁止POST
func ShowMode() gin.HandlerFunc {
return func(c *gin.Context) {
// 路由转权限
auths := strings.ReplaceAll(strings.Replace(c.Request.URL.Path, "/api/", "", 1), "/", ":")
// 禁止修改操作 (演示功能,限制POST请求)
if c.Request.Method == "POST" && !util.ToolsUtil.Contains(config.AdminConfig.ShowWhitelistUri, auths) {
response.FailWithMsg(c, response.NoPermission, "演示环境不支持修改数据,请下载源码本地部署体验!")
c.Abort()
return
}
}
}