(path string, all ...bool)
| 52 | } |
| 53 | |
| 54 | func EncodePath(path string, all ...bool) string { |
| 55 | seg := strings.Split(path, "/") |
| 56 | toReplace := []struct { |
| 57 | Src string |
| 58 | Dst string |
| 59 | }{ |
| 60 | {Src: "%", Dst: "%25"}, |
| 61 | {"%", "%25"}, |
| 62 | {"?", "%3F"}, |
| 63 | {"#", "%23"}, |
| 64 | } |
| 65 | for i := range seg { |
| 66 | if len(all) > 0 && all[0] { |
| 67 | seg[i] = url.PathEscape(seg[i]) |
| 68 | } else { |
| 69 | for j := range toReplace { |
| 70 | seg[i] = strings.ReplaceAll(seg[i], toReplace[j].Src, toReplace[j].Dst) |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | return strings.Join(seg, "/") |
| 75 | } |
| 76 | |
| 77 | func JoinBasePath(basePath, reqPath string) (string, error) { |
| 78 | /** relative path: |
no outgoing calls