geoip

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

README

ContainerSSH IP to Country Code Library

This library provides IP to Country Code lookup services for ContainerSSH.

Using this library

This library needs a configuration structure described in config.go in the public package. This configuration structure can be passed to the geoip.New() method:

provider, err := geoip.New(geoip.Config{
    // Can be "dummy" or "maxmind".
    Provider: "maxmind",
    // MMDB2 file for the MaxMind provider.
    GeoIP2File: "/path/to/maxmind/file.mmdb2",
})
if err != nil {
    // handle error
}

The GeoIP lookup can be performed using the Lookup() method:

countryCode := provider.Lookup("127.0.0.1")

The countryCode field will contain the value of XX if the lookup failed.

Implementing a lookup provider

A custom provider can be written by implementing the following interface:

type LookupProvider interface {
	Lookup(remoteAddr net.IP) (countryCode string)
}

Once implemented you will need to add the necessary configuration options to config.go and add a factory method to factory.go.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

New creates a new lookup provider based on the configuration.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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