Documentation ¶
Overview ¶
Package geoip is a library that allows you to find the external IP of a system. This implementation is based on the github.com/GlenDC/go-external-ip library.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoIP = errors.New("no IP could be found")
ErrNoIP is returned when no IP could be found.
Functions ¶
This section is empty.
Types ¶
type Consensus ¶
type Consensus struct {
// contains filtered or unexported fields
}
Consensus the type at the center of this library, and is the main entry point for users. Its `ExternalIP` method allows you to ask for your ExternalIP, influenced by all its added voters.
func DefaultConsensus ¶
DefaultConsensus returns a consensus filled with default and recommended HTTPSources. TLS-Protected providers get more power, compared to plain-text providers.
func NewConsensus ¶
NewConsensus creates a new Consensus, with no sources.
func (*Consensus) AddVoter ¶
AddVoter adds a voter to this consensus. The source cannot be <nil> and the weight has to be of a value of 1 or above.
func (*Consensus) ResolveExternalIP ¶
ResolveExternalIP resolves the externalIP from all added voters, returning the IP which received the most votes. The returned IP will always be valid, in case the returned error is <nil>.
func (*Consensus) UseIPProtocol ¶
UseIPProtocol will set the IP Protocol to use for http requests to the sources. If zero, it will not discriminate. This is useful when you want to get the external IP in a specific protocol. Protocol only supports 0, 4 or 6.
type ContentParser ¶
ContentParser can be used to add a parser to an HTTPSource to parse the raw content returned from a website, and return the IP. Spacing before and after the IP will be trimmed by the Consensus.
type HTTPSource ¶
type HTTPSource struct {
// contains filtered or unexported fields
}
HTTPSource is the default source, to get the external IP from. It does so by requesting the IP from a URL, via an HTTP GET Request.
func NewHTTPSource ¶
func NewHTTPSource(url string) *HTTPSource
NewHTTPSource creates a HTTP Source object, which can be used to request the (external) IP from. The Default HTTP Client will be used if no client is given.
func (*HTTPSource) WithParser ¶
func (s *HTTPSource) WithParser(parser ContentParser) *HTTPSource
WithParser sets the parser value as the value to be used by this HTTPSource, and returns the pointer to this source, to allow for chaining.
type Source ¶
type Source interface { // IP returns IPv4/IPv6 address in a non-error case // net.IP should never be <nil> when error is <nil> // It is recommended that the IP function times out, // if no result could be found, after the given timeout duration. IP(ctx context.Context, protocol uint) (net.IP, error) }
Source defines the part of a voter which gives the actual voting value (IP).