hostport

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const NoPort = -1

Variables

This section is empty.

Functions

func HasPort

func HasPort(s string) bool

HasPort returns true if the provided address does not include a port number.

func NormalizeHost

func NormalizeHost(s string, forceFQDN bool) (string, error)

NormalizeHost returns normalized representation of host (Punycode for DNS names, standardized IP address representation).

If forceFQDN is true, returned normalized domain name will include a trailing dot.

func NormalizePort

func NormalizePort(s string) (port int, err error)

NormalizePort converts `s` to int if it represents a valid TCP port.

Types

type HostPort

type HostPort struct {
	Host string
	Port int
}

func New

func New(s string, forceFQDN bool) (hostport HostPort, err error)

New takes a colon-separated host and port and returns a normalized representation of host (Punycode for DNS names, standardized IP address representation) and a port number.

`s` argument needs to conform to `authority-form` as defined by https://datatracker.ietf.org/doc/html/rfc7230#section-5.3.3. In particular, port must be provided.

If forceFQDN is true, returned normalized domain name will be an FQDN.

func NewWithScheme

func NewWithScheme(s, scheme string, forceFQDN bool) (hostport HostPort, err error)

NewWithScheme returns host (as string) and port (as int) normalized with `normalizeHost` and `normalizePort`.

`s` is a bare host or a colon-separated (':') host name and port. If no port is specified, the `scheme` string is used to find the default port (https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3).

If forceFQDN is true, returned normalized domain name will be an FQDN.

func (HostPort) FQDN

func (hp HostPort) FQDN() string

func (HostPort) IsFQDN

func (hp HostPort) IsFQDN() bool

func (HostPort) IsIP

func (hp HostPort) IsIP() bool

func (HostPort) String

func (hp HostPort) String() string

Jump to

Keyboard shortcuts

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