Skip to content
This repository has been archived by the owner on Oct 2, 2022. It is now read-only.
/ geoip Public archive
generated from ContainerSSH/library-template

The GeoIP lookup library for ContainerSSH

License

Notifications You must be signed in to change notification settings

ContainerSSH/geoip

ContainerSSH - Launch Containers on Demand

ContainerSSH IP to Country Code Library

⚠⚠⚠ Deprecated: ⚠⚠⚠
This repository is deprecated in favor of libcontainerssh for ContainerSSH 0.5.

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

Using this library

This library needs a configuration structure described in config.go. 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.