endpointaddr

package
v0.34.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package endpointaddr implements parsing and validation of "<host>[:<port>]" strings for Pinniped APIs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HostPort

type HostPort struct {
	// Host is the validated host part of the input, which may be a hostname or IP.
	//
	// This string can be used as a x509 certificate SAN.
	Host string

	// Port is the validated port number, which may be defaulted.
	Port uint16
}

func Parse

func Parse(endpoint string, defaultPort uint16) (HostPort, error)

Parse an "endpoint address" string, providing a default port. The input can be in several valid formats:

- "<hostname>" (DNS hostname) - "<IPv4>" (IPv4 address) - "<IPv6>" (IPv6 address) - "<hostname>:<port>" (DNS hostname with port) - "<IPv4>:<port>" (IPv4 address with port) - "[<IPv6>]:<port>" (IPv6 address with port, brackets are required)

If the input does not specify a port number, then defaultPort will be used.

func ParseFromURL added in v0.30.0

func ParseFromURL(u *url.URL, defaultPort uint16) (HostPort, error)

ParseFromURL wraps Parse but specifically takes a url.URL instead of an endpoint string. ParseFromURL differs from Parse in that IPv6 addresses must be wrapped in brackets when used in a URL (even when used without a port).

If the input does not specify a port number, then defaultPort will be used.

The RFC for literal IPv6 addresses in URLs indicates that brackets - must be used when a port is provided - should be used when a port is not provided, but does not indicate "must" See https://datatracker.ietf.org/doc/html/rfc2732#section-2

However, the Golang docs make it clear that IPv6 addresses must be wrapped in brackets when used in a URL. See https://pkg.go.dev/net/url#URL

Note that ParseFromURL returns a HostPort which has an Endpoint() method which will return a properly constructed URL with brackets when appropriate.

func (*HostPort) Endpoint

func (h *HostPort) Endpoint() string

Endpoint is the host:port validated from the input, where port may be a default value.

This string can be passed to net.Dial.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL