hostutil

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package hostutil provides utilities for working with host addresses.

It includes functions for composing host addresses from specified addresses, ports, and default ports. The package supports various formats for the address and inserts a default port if one is not specified in the address.

The ComposeAddress function composes a single host address, while the ComposeAddresses function composes multiple host addresses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComposeAddress

func ComposeAddress(address, port, defaultPort string) string

ComposeAddress composes host address from a specified address, port and a default port. Supported formats for address are:

  • host
  • host:port
  • :port
  • host:

The method inserts specified defaultPort if port is omitted in address provided. The method panics if defaultPort is not specified. If address is empty, method will return address in form of ":defaultPort".

func ComposeAddressList

func ComposeAddressList(addresses string, port, defaultPort string) []string

ComposeAddressList composes host addresses from a specified addresses, port and a default port. Multiple addresses are delimited with comma or semi-column.

func ComposeAddresses

func ComposeAddresses(addresses []string, port, defaultPort string) []string

ComposeAddresses composes host addresses from a specified addresses, port and a default port.

Types

type HostPort

type HostPort struct {
	Host string
	Port string
}

HostPort encapsulates host and port.

func NewHostPort

func NewHostPort(address, port, defaultPort string) HostPort

NewHostPort composes HostPort from a specified address, port and a default port. Supported formats for address are:

  • host
  • host:port
  • :port
  • host:

The method inserts specified defaultPort if port is omitted in address provided. The method panics if defaultPort is not specified. If address is empty, method will return address in form of ":defaultPort".

func (HostPort) String

func (h HostPort) String() string

String implements Stringer interface.

Jump to

Keyboard shortcuts

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