MCPcopy Create free account
hub / github.com/APIParkLab/APIPark / formatProxyPath

Function formatProxyPath

gateway/apinto/entity/router.go:190–206  ·  view source on GitHub ↗

formatProxyPath 格式化转发路径上,用于转发重写插件正则替换 比如 请求路径 /path/{A}/{B} 原转发路径:/path/{B} 格式化后 新转发路径: /path/$2

(requestPath, proxyPath string)

Source from the content-addressed store, hash-verified

188
189// formatProxyPath 格式化转发路径上,用于转发重写插件正则替换 比如 请求路径 /path/{A}/{B} 原转发路径:/path/{B} 格式化后 新转发路径: /path/$2
190func formatProxyPath(requestPath, proxyPath string) string {
191 restfulSet := make(map[string]string)
192 newProxyPath := proxyPath
193 rList := strings.Split(requestPath, "/")
194 i := 1
195 for _, param := range rList {
196 if common.IsRestfulParam(param) {
197 restfulSet[param] = fmt.Sprintf("$%d", i)
198 i += 1
199 }
200 }
201
202 for param, order := range restfulSet {
203 newProxyPath = strings.ReplaceAll(newProxyPath, param, order)
204 }
205 return newProxyPath
206}

Callers 1

ToRouterFunction · 0.85

Calls 1

IsRestfulParamFunction · 0.92

Tested by

no test coverage detected