baseURL returns the concatenation of the scheme and host parts of serverBaseURL with the port of listenAddr.
(serverBaseURL, listenAddr string)
| 267 | // baseURL returns the concatenation of the scheme and host parts of |
| 268 | // serverBaseURL with the port of listenAddr. |
| 269 | func baseURL(serverBaseURL, listenAddr string) (string, error) { |
| 270 | backendURL, err := url.Parse(serverBaseURL) |
| 271 | if err != nil { |
| 272 | return "", fmt.Errorf("invalid baseURL %q: %v", serverBaseURL, err) |
| 273 | } |
| 274 | scheme := backendURL.Scheme |
| 275 | host := backendURL.Host |
| 276 | if netutil.HasPort(host) { |
| 277 | host = host[:strings.LastIndex(host, ":")] |
| 278 | } |
| 279 | port := portMap[scheme] |
| 280 | if netutil.HasPort(listenAddr) { |
| 281 | port = listenAddr[strings.LastIndex(listenAddr, ":")+1:] |
| 282 | } |
| 283 | return fmt.Sprintf("%s://%s:%s/", scheme, host, port), nil |
| 284 | } |
| 285 | |
| 286 | // TODO(mpl): some way to avoid the redundancy with serverconfig.App would be |
| 287 | // nice. But at least HandlerConfig and its doc is cleaner than having to document a |