netx

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2020 License: BSD-2-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JoinHostPort

func JoinHostPort(host string, port uint16) string

JoinHostPort combines host and port into a network address of the form "host:port". If host contains a colon, as found in literal IPv6 addresses, then JoinHostPort returns "[host]:port".

func SplitHostPort

func SplitHostPort(str string) (string, uint16, error)

SplitHostPort splits a network address of the form "host:port", "host%zone:port", "[host]:port" or "[host%zone]:port" into host or host%zone and port. If port part not exists, or is not a valid port, return an error.

Types

type Address

type Address struct {
	// contains filtered or unexported fields
}

Address contains a host part, and an optional port part. This struct is designed to be immutable

func NewAddress

func NewAddress(host string, port uint16) *Address

Create new address with port

func NewAddressWithoutPort

func NewAddressWithoutPort(host string) *Address

Create new address without port

func ParseAddress

func ParseAddress(addressStr string) (*Address, error)

Parse address from string

func (*Address) HasPort

func (a *Address) HasPort() bool

Return if address has port part

func (*Address) Host

func (a *Address) Host() string

Return the host of address

func (*Address) Port

func (a *Address) Port() (uint16, bool)

Return the port of address, if does not has a port, return false as second value

func (*Address) PortOrDefault

func (a *Address) PortOrDefault(defaultPort uint16) uint16

Return the port of address, if does not has a port, return default port

func (*Address) String

func (a *Address) String() string

Convert to address string

func (*Address) WithPortIfMissing

func (a *Address) WithPortIfMissing(port uint16) *Address

If port is missing, return a new Address with port specified; else return original address.

type HostType

type HostType int8

HostType is an enum to distinct host type, can be domain, ipv4, or ipv6

const (
	// Not a host
	ILLEGAL HostType = -1
	// domain host
	DOMAIN HostType = 0
	// ipv4 address host
	IPv4 HostType = 1
	// ipv6 address host
	IPv6 HostType = 2
)

func GetHostType

func GetHostType(host string) HostType

GetHostType return type for this host

Jump to

Keyboard shortcuts

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