MCPcopy
hub / github.com/perkeep/perkeep / baseURL

Function baseURL

pkg/server/app/app.go:269–284  ·  view source on GitHub ↗

baseURL returns the concatenation of the scheme and host parts of serverBaseURL with the port of listenAddr.

(serverBaseURL, listenAddr string)

Source from the content-addressed store, hash-verified

267// baseURL returns the concatenation of the scheme and host parts of
268// serverBaseURL with the port of listenAddr.
269func 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

Callers 2

TestBaseURLFunction · 0.70
NewHandlerFunction · 0.70

Calls 2

HasPortFunction · 0.92
ParseMethod · 0.80

Tested by 1

TestBaseURLFunction · 0.56