joinPathWithHostPrefix builds a full REST API URL by prepending hostPrefix to the path produced by JoinPath. A single slash is ensured at the join between hostPrefix and the path so they separate cleanly without doubling up. When hostPrefix is empty, the JoinPath result is returned intact, and when
(hostPrefix string, components ...string)
| 150 | // when the joined path is empty, hostPrefix is returned intact. hostPrefix is used verbatim while each |
| 151 | // component is percent-encoded. |
| 152 | func joinPathWithHostPrefix(hostPrefix string, components ...string) string { |
| 153 | path := joinPath(components...) |
| 154 | if hostPrefix == "" { |
| 155 | return path |
| 156 | } |
| 157 | if path == "" { |
| 158 | return hostPrefix |
| 159 | } |
| 160 | if !strings.HasSuffix(hostPrefix, "/") { |
| 161 | return hostPrefix + "/" + path |
| 162 | } |
| 163 | return hostPrefix + path |
| 164 | } |