address

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetIPByDomain

func GetIPByDomain(address string) (*string, error)

GetIPByDomain performs a DNS lookup to retrieve the IP address associated with the provided domain. It takes the domain name as input and returns the IP address and nil error if successful, otherwise returns nil and an error.

func GetPublicIP

func GetPublicIP() net.IP

GetPublicIP retrieves the public IP address using the default consensus and returns it. It returns the public IP address if successful, otherwise returns nil.

func ParseIP

func ParseIP(address string) (*string, error)

ParseIP parses the given IP address and returns the parsed IP and nil error if successful, otherwise returns nil and an error. If the provided IP is a loopback or unspecified IP, it replaces it with the public IP.

Types

type Endpoint

type Endpoint struct {
	IP      *string
	Host    *string
	Path    *string
	Port    *string
	Address string
	SSL     bool
}

func ParseIPPort added in v1.2.1

func ParseIPPort(address string) (*Endpoint, error)

ParseIpPort parses the given address and returns an Endpoint and an error. If the address is in the format "ip:port", it returns the IP and port as an Endpoint. If the address is in the format "protocol/ip4/host/udp/port", it returns the host and port as an Endpoint. If the IP provided is a loopback or unspecified IP, it replaces it with the public IP. Returns the parsed Endpoint and nil error if successful, otherwise returns nil and an error.

func ParsePeer

func ParsePeer(address string) (*Endpoint, error)

ParsePeer parses the given address and returns an Endpoint and an error. If the address is in the format "/ip4/host/udp/port", it returns the host and port as an Endpoint. If the IP provided is a loopback or unspecified IP, it replaces it with the public IP. Returns the parsed Endpoint and nil error if successful, otherwise returns nil and an error.

func ParseURL

func ParseURL(address string) (*Endpoint, error)

ParseURL parses the given address and returns an Endpoint and an error. If the address does not start with "http", it adds "http://" to the beginning of the address. It then parses the address using the url.Parse function and constructs an Endpoint with the parsed information. Returns the parsed Endpoint and nil error if successful, otherwise returns nil and an error.

func (*Endpoint) GetHostWithPath

func (hp *Endpoint) GetHostWithPath() *string

GetHostWithPath returns the host with the path, if available. If the host is nil, it returns nil. Otherwise, it concatenates the host and path and returns the result. Returns a pointer to the concatenated host with the path.

Jump to

Keyboard shortcuts

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