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)
| 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. |
| 252 | func 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. |
no test coverage detected