Ai
1 Star 1 Fork 0

灵狐/go-fox-edge-kernel-common

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
GatewayRouterVO.go 2.16 KB
一键复制 编辑 原始数据 按行查看 历史
灵狐 提交于 2024-10-23 13:33 +08:00 . 初始化
package gatewayRouter
import (
"errors"
"strings"
)
type RouterVO struct {
Id string `json:"id"` // json字段
Uri string `json:"uri"` // json字段
Order int `json:"order"` // json字段
Predicates []map[string]interface{} `json:"predicates"` // json字段
Filters []map[string]interface{} `json:"filters"` // json字段
Metadata map[string]interface{} `json:"metadata"` // json字段
}
// BuildVO 使用范例:BuildVO("service","channel-serialport-native","/service/channel-serialport-native/**",""http://localhost:9201/service/channel-serialport-native")
func (e *RouterVO) buildVO(serviceType string, serviceName string, serviceUri string, redirectUri string) *RouterVO {
vo := &RouterVO{}
vo.Id = serviceType + ":" + serviceName
vo.Uri = redirectUri
vo.Metadata = make(map[string]interface{})
vo.Order = 0
// predicates
vo.Predicates = make([]map[string]interface{}, 0)
predicate := make(map[string]interface{})
predicate["name"] = "Path"
args := make(map[string]interface{})
args["_genkey_0"] = serviceUri
predicate["args"] = args
vo.Predicates = append(vo.Predicates, predicate)
// filters
vo.Filters = make([]map[string]interface{}, 0)
filters := make(map[string]interface{})
filters["name"] = "StripPrefix"
args = make(map[string]interface{})
args["_genkey_0"] = 2
filters["args"] = args
vo.Filters = append(vo.Filters, filters)
return vo
}
func (e *RouterVO) getParams() (string, string, string, error) {
if len(e.Predicates) == 0 {
return "", "", "", errors.New("predicates缺失")
}
predicate := e.Predicates[0]
val, ok := predicate["args"]
if !ok {
return "", "", "", errors.New("predicates.args缺失")
}
args := val.(map[string]interface{})
val, ok = args["_genkey_0"]
if !ok {
return "", "", "", errors.New("predicates.args._genkey_0缺失")
}
serviceUri := val.(string)
// 分拆数据:获得http://localhost:9101/kernel/manager中的http://localhost:9101部分
idx := strings.Index(e.Uri, "://") + len("://")
idx += strings.Index(e.Uri[idx:len(e.Uri)], "/")
uri := e.Uri[0:idx]
return e.Id, uri, serviceUri, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/fierce_wolf/go-fox-edge-kernel-common.git
git@gitee.com:fierce_wolf/go-fox-edge-kernel-common.git
fierce_wolf
go-fox-edge-kernel-common
go-fox-edge-kernel-common
v1.0.1

搜索帮助