MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / parseAddress

Function parseAddress

pkg/basicstation/cups/server.go:232–268  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

230//
231//nolint:revive,nakedret
232func 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
270func (s *Server) getTrust(address string) (*x509.Certificate, error) {
271 if address == "" {

Callers 2

getTrustMethod · 0.85
updateInfoMethod · 0.85

Calls 2

ContainsMethod · 0.65
ParseMethod · 0.65

Tested by

no test coverage detected