publicAddress

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: BSD-2-Clause Imports: 12 Imported by: 1

Documentation

Overview

Package publicAddress contains a utility to retrieve the callers public IP address.

Index

Constants

View Source
const (
	DefaultPollTimeout = 65 * time.Second
)

Variables

This section is empty.

Functions

func GetIP

func GetIP(lookupServices []Service, timeout time.Duration) (string, error)

GetIP returns the caller's public IPv4 address. Multiple services are checked until one returns an IP address or the time out is reached.

func GetIpOverride

func GetIpOverride(overrideIP string, port int) (string, error)

GetIpOverride returns the public IP of the caller or the override IP, if it is supplied. If overrideIP is empty, then the caller's IP is looked up, joined with the port, and returned. If the overrideIP is supplied, then it is joined with the port and returned. If the overrideIP has a port, then it is returned as is.

func JoinIpPort

func JoinIpPort(ip string, port int) (string, error)

JoinIpPort joins the ip and port together. If the ip already has a port, it is returned as is.

Types

type Service

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

Service structure contains the URL to an IP lookup Service and which IP version it returns.

func MakeTestLookupService

func MakeTestLookupService(ip string, i interface{}) ([]Service, *httptest.Server)

MakeTestLookupService creates a test server and service list containing the IP of that server. The server will respond with the provided address. This function is intended for testing only so that tests do not need to reach an external service to function. Once the returned server is used, it should be closed using ts.Close().

Jump to

Keyboard shortcuts

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