net

package
v0.0.0-...-d5852c7 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2020 License: MIT Imports: 6 Imported by: 0

README

Net

Additional networking utilities and helpers

Documentation

Overview

Package net provides additional networking utilities and helpers.

Index

Constants

View Source
const DefaultPort = 3264

DefaultPort is used to allocate a port for services on the network when not specified directly. The port number refers to our office in A.V. Williams during graduate school and we've commonly used it in many applications. The DefaultPort is primarily used in ResolveAddr.

Variables

This section is empty.

Functions

func ExternalIP

func ExternalIP() (string, error)

ExternalIP looks up an the first available external IP address used by local network interfaces. This function returns a string representation of the IP address that can be parsed by net.IPAddr or other tools.

NOTE: this function does not refer to the external network IP address, but rather non-local or loopback addresses on the machine. If the machine receives an internal DHCP provied IP address, then this function will detect that, not the IP address of the router. To find the publically accessible IP address of the machine use PublicIP.

func FreePort

func FreePort() (int, error)

FreePort asks the kernel for a free, open port that is ready to use. https://github.com/phayes/freeport

func PublicIP

func PublicIP() (string, error)

PublicIP makes an external HTTP request to myexternalip.com in order to discover the publically available IP address of the machine. This is especially useful when the machine sits behind a NAT device such as a router that performs port forwarding.

NOTE: the myexternalip.com service maintains a rate limit of 30 requests per minute, do not exceed it!

func ResolveAddr

func ResolveAddr(addr string) (string, error)

ResolveAddr accepts an address as a string and if the IP address is missing it replaces it with the result from ExternalIP then returns the addr string. Likewise if the Port is missing, it returns an address with the DefaultPort appended to the address string.

Types

This section is empty.

Jump to

Keyboard shortcuts

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