geoip

package
v0.0.0-...-672176f Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

database configs

func New

func New(opts ...func(*Config)) (*Config, error)

New returns a new Config with the given options

func (*Config) Close

func (c *Config) Close() error

Close closes the database connection

func (*Config) Lookup

func (c *Config) Lookup(ip net.IP) (*GeoIPData, error)

Lookip GeoIP data for the given IP address.

type GeoIPData

type GeoIPData struct {
	IP          net.IP  `json:"ip"`
	City        string  `json:"city_name"`
	Continent   string  `json:"continent_code"`
	Country     string  `json:"country_code"`
	Latitude    float64 `json:"latitude"`
	Longitude   float64 `json:"longitude"`
	MetroCode   uint    `json:"metro_code"`
	TimeZone    string  `json:"time_zone"`
	PostalCode  string  `json:"postal_code"`
	Subdivision string  `json:"subdivision_code"`
}

GeoIPData represents the data returned.

type Option

type Option func(c *Config)

Used to manage varidic options

func SetGeoDB

func SetGeoDB(geodb string) Option

SetGeoDB sets the database location

type Record

type Record struct {
	City struct {
		Names map[string]string `maxminddb:"names"`
	} `maxminddb:"city"`

	Continent struct {
		Code string `maxminddb:"code"`
	} `maxminddb:"continent"`

	Country struct {
		IsoCode string `maxminddb:"iso_code"`
	} `maxminddb:"country"`

	Location struct {
		AccuracyRadius uint16  `maxminddb:"accuracy_radius"`
		Latitude       float64 `maxminddb:"latitude"`
		Longitude      float64 `maxminddb:"longitude"`
		MetroCode      uint    `maxminddb:"metro_code"`
		TimeZone       string  `maxminddb:"time_zone"`
	} `maxminddb:"location"`

	Postal struct {
		Code string `maxminddb:"code"`
	} `maxminddb:"postal"`

	Subdivisions []struct {
		IsoCode string `maxminddb:"iso_code"`
	} `maxminddb:"subdivisions"`
}

Record defines the fields to fetch from the GeoIP database.

Jump to

Keyboard shortcuts

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