geoip

package
v0.7.10 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingDB indicates that one or more of the utility databases was not provided. The wrapped
	// error message should indicate which database was missing.
	ErrMissingDB = errors.New("missing one or more geoip DBs")
)
View Source
var (
	// ErrNoDatabasesProvided indicates that no databases were provided so we are going to return a
	// struct implementing the Database interface so stations that don't support geoip can still
	// operate normally.
	ErrNoDatabasesProvided = errors.New("no databases provided - using empty Geoip")
)

Functions

This section is empty.

Types

type DBConfig

type DBConfig struct {
	CCDBPath  string `toml:"geoip_cc_db_path"`
	ASNDBPath string `toml:"geoip_asn_db_path"`
}

DBConfig contains options used for GeoIP lookup - including paths to database files

type Database

type Database interface {
	ASN(ip net.IP) (uint, error)
	CC(ip net.IP) (string, error)
}

Database provides the minimal useful interface for looking up relevant information so we aren't tied tp the types / interface of a specific GeoIP library

func New

func New(conf *DBConfig) (Database, error)

New returns a database given a config. If the provided config is nil, the Empty Database will be returned.

type EmptyDatabase

type EmptyDatabase struct {
}

EmptyDatabase provides the Geoip functionality that we need using the MaxMind GeoIP service

func (*EmptyDatabase) ASN

func (mmdb *EmptyDatabase) ASN(ip net.IP) (uint, error)

ASN returns the Autonomous System Number (ASN) associated with the provided IP. The Empty Database Returns 0.

func (*EmptyDatabase) CC

func (mmdb *EmptyDatabase) CC(ip net.IP) (string, error)

CC returns the ISO country code associated with the provided IP. The Empty Database Returns an empty string.

Jump to

Keyboard shortcuts

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