address

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2021 License: MIT Imports: 10 Imported by: 2

README

Emitter address

This golang package is used for IP/hardware address parsing for emitter.io. This provides a simple way of parsing a variety of IP addresses and, in future, domain names.

Build status Coverage Status Go Report Card

Installation

go get -u github.com/emitter-io/address

API Documentation

For full API documentation, please refer to our godoc.org/github.com/emitter-io/address which contains all of the methods that package exposes.

Parsing IP Addresses

Typical usage consists of calling parse function which provides a set of helpers such as (e.g. private, public and external) which then get appropriately parsed to the TCP IP Address, as demonstrated below.

addr, err := address.Parse("external:8080")

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Loopback = net.IPAddr{IP: net.ParseIP("127.0.0.1")}

Loopback is the default loopback address (127.0.0.1)

Functions

func GetExternal

func GetExternal() (net.IPAddr, error)

GetExternal returns an externally visible IP Address. This actually goes out to the internet service which echoes the address.

func GetExternalOrDefault

func GetExternalOrDefault(defaultAddr net.IPAddr) net.IPAddr

GetExternalOrDefault returns an externally visible IP Address. If no address is available, this defaults to the specified default address.

func GetPrivate

func GetPrivate() ([]net.IPAddr, error)

GetPrivate returns the list of private network IPv4 addresses on all active interfaces.

func GetPrivateOrDefault

func GetPrivateOrDefault(addr net.IPAddr) net.IPAddr

GetPrivateOrDefault returns the first private IPv4 address. If no address is available, this defaults to the specified default address.

func GetPublic

func GetPublic() ([]net.IPAddr, error)

GetPublic returns the list of all public IP addresses on all active interfaces.

func GetPublicOrDefault

func GetPublicOrDefault(addr net.IPAddr) net.IPAddr

GetPublicOrDefault returns the first public IP address. If no address is available, this defaults to the specified default address.

func Parse

func Parse(addr string, defaultPort int) (*net.TCPAddr, error)

Parse parses a TCP address + port combination.

func Resolve

func Resolve(name string, defaultPort int) ([]net.TCPAddr, error)

Resolve resolves the addresses behind a hostname or a URL. This supports only TCP (as pretty much everything in the package) but can handle a URL passed instead of the name (e.g. https://example.com).

Types

type Fingerprint

type Fingerprint uint64

Fingerprint represents hardware fingerprint

func GetHardware

func GetHardware() Fingerprint

GetHardware retrieves the hardware address fingerprint which is based on the address of the first interface encountered.

func (Fingerprint) Hex

func (f Fingerprint) Hex() string

Hex returns the string in hex format.

func (Fingerprint) String

func (f Fingerprint) String() string

String encodes PeerName as a string.

Jump to

Keyboard shortcuts

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