parseAddress parses a CUPS or LNS address. It supports the typical format "host:port" (port being optional). It allows schemes "http://host:port" to be present. If schemes http/https/ws/wss are used, the port is inferred if not present. nolint:revive,nakedret
(defaultScheme, address string)
| 230 | // |
| 231 | //nolint:revive,nakedret |
| 232 | func parseAddress(defaultScheme, address string) (scheme, host, port string, err error) { |
| 233 | if address == "" { |
| 234 | return |
| 235 | } |
| 236 | if strings.Contains(address, "://") { |
| 237 | url, err := url.Parse(address) |
| 238 | if err != nil { |
| 239 | return "", "", "", err |
| 240 | } |
| 241 | scheme, address = url.Scheme, url.Host |
| 242 | } |
| 243 | if strings.Contains(address, ":") { |
| 244 | host, port, err = net.SplitHostPort(address) |
| 245 | if err != nil { |
| 246 | host = address |
| 247 | err = nil |
| 248 | } |
| 249 | } else { |
| 250 | host = address |
| 251 | } |
| 252 | if scheme == "" { |
| 253 | scheme = defaultScheme |
| 254 | } |
| 255 | if port == "" { |
| 256 | switch scheme { |
| 257 | case "http": |
| 258 | port = "80" |
| 259 | case "ws": |
| 260 | port = "1887" |
| 261 | case "https": |
| 262 | port = "443" |
| 263 | case "wss": |
| 264 | port = "8887" |
| 265 | } |
| 266 | } |
| 267 | return |
| 268 | } |
| 269 | |
| 270 | func (s *Server) getTrust(address string) (*x509.Certificate, error) { |
| 271 | if address == "" { |
no test coverage detected