MCPcopy
hub / github.com/perkeep/perkeep / cleanServer

Function cleanServer

pkg/client/config.go:252–264  ·  view source on GitHub ↗

cleanServer returns the canonical URL of the provided server, which must be a URL, IP, host (with dot), or host/ip:port. The returned canonical URL will have trailing slashes removed and be prepended with "https://" if no scheme is provided.

(server string)

Source from the content-addressed store, hash-verified

250// cleanServer returns the canonical URL of the provided server, which must be a URL, IP, host (with dot), or host/ip:port.
251// The returned canonical URL will have trailing slashes removed and be prepended with "https://" if no scheme is provided.
252func cleanServer(server string) (string, error) {
253 if !isURLOrHostPort(server) {
254 return "", fmt.Errorf("server %q does not look like a server address and could be confused with a server alias. It should look like [http[s]://]foo[.com][:port] with at least one of the optional parts.", server)
255 }
256 // Remove trailing slash if provided.
257 server = strings.TrimSuffix(server, "/")
258
259 // Default to "https://" when not specified
260 if !strings.HasPrefix(server, "http://") && !strings.HasPrefix(server, "https://") {
261 server = "https://" + server
262 }
263 return server, nil
264}
265
266// getServer returns the server's URL found either as a command-line flag,
267// or as the default server in the config file.

Callers 3

parseConfigMethod · 0.85
getServerFunction · 0.85
defaultServerFunction · 0.85

Calls 2

isURLOrHostPortFunction · 0.85
HasPrefixMethod · 0.80

Tested by

no test coverage detected