formatProxyPath 格式化转发路径上,用于转发重写插件正则替换 比如 请求路径 /path/{A}/{B} 原转发路径:/path/{B} 格式化后 新转发路径: /path/$2
(requestPath, proxyPath string)
| 188 | |
| 189 | // formatProxyPath 格式化转发路径上,用于转发重写插件正则替换 比如 请求路径 /path/{A}/{B} 原转发路径:/path/{B} 格式化后 新转发路径: /path/$2 |
| 190 | func 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 | } |
no test coverage detected