3 Star 12 Fork 3

os-lee/easy-paas

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
strip_uri.go 850 Bytes
一键复制 编辑 原始数据 按行查看 历史
lee 提交于 2024-07-11 15:01 +08:00 . websocket路由支持url重写,负载均衡
package middleware_ws
import (
"gitee.com/os-lee/easy-paas/common"
"gitee.com/os-lee/easy-paas/common/e"
"gitee.com/os-lee/easy-paas/gateway/internal/dao"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
"strings"
)
// StripUri uri去掉前缀
func StripUri() gin.HandlerFunc {
return func(c *gin.Context) {
serverInterface, ok := c.Get("service")
if !ok {
common.ResponseError(c, e.ErrGateway, errors.New("从上下文中获取服务失败"))
c.Abort()
return
}
serviceDetail := serverInterface.(*dao.ServiceDetail)
if serviceDetail.HTTPRule.RuleType == common.RuleTypePrefixURL && serviceDetail.HTTPRule.NeedStripUri == 1 {
c.Request.URL.Path = strings.Replace(c.Request.URL.Path, serviceDetail.HTTPRule.Rule, "", 1)
}
//例如
//http://127.0.0.1:8080/test/abbb
//http://127.0.0.1:2004/abbb
c.Next()
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/os-lee/easy-paas.git
git@gitee.com:os-lee/easy-paas.git
os-lee
easy-paas
easy-paas
6cf1638f64c0

搜索帮助