geoip2: github.com/savaki/geoip2 Index | Examples | Files | Directories

package geoip2

import "github.com/savaki/geoip2"

Index

Examples

Package Files

geoip2.go types.go

type Api Uses

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

func New Uses

func New(userId, licenseKey string) *Api

func WithClient Uses

func WithClient(api *Api, client *http.Client) *Api

func WithClientFunc Uses

func WithClientFunc(api *Api, ctxFunc func(context.Context, *http.Request) (*http.Response, error)) *Api

func (*Api) City Uses

func (a *Api) City(ctx context.Context, ipAddress string) (Response, error)

Code:

userId := os.Getenv("MAXMIND_USER_ID")
licenseKey := os.Getenv("MAXMIND_LICENSE_KEY")
api := geoip2.New(userId, licenseKey)

resp, _ := api.City(nil, "1.2.3.4")
json.NewEncoder(os.Stdout).Encode(resp)

func (*Api) Country Uses

func (a *Api) Country(ctx context.Context, ipAddress string) (Response, error)

Code:

userId := os.Getenv("MAXMIND_USER_ID")
licenseKey := os.Getenv("MAXMIND_LICENSE_KEY")
api := geoip2.New(userId, licenseKey)

ctx, _ := context.WithTimeout(context.Background(), 3*time.Second)
resp, _ := api.Country(ctx, "1.2.3.4")
json.NewEncoder(os.Stdout).Encode(resp)

func (*Api) Insights Uses

func (a *Api) Insights(ctx context.Context, ipAddress string) (Response, error)

Code:

userId := os.Getenv("MAXMIND_USER_ID")
licenseKey := os.Getenv("MAXMIND_LICENSE_KEY")
api := geoip2.New(userId, licenseKey)

ctx, _ := context.WithTimeout(context.Background(), 3*time.Second)
resp, _ := api.Insights(ctx, "1.2.3.4")
json.NewEncoder(os.Stdout).Encode(resp)

type City Uses

type City struct {
    Confidence int               `json:"confidence,omitempty"`
    GeoNameId  int               `json:"geoname_id,omitempty"`
    Names      map[string]string `json:"names,omitempty"`
}

type Continent Uses

type Continent struct {
    Code      string            `json:"code,omitempty"`
    GeoNameId int               `json:"geoname_id,omitempty"`
    Names     map[string]string `json:"names,omitempty"`
}

type Country Uses

type Country struct {
    Confidence int               `json:"confidence,omitempty"`
    GeoNameId  int               `json:"geoname_id,omitempty"`
    IsoCode    string            `json:"iso_code,omitempty"`
    Names      map[string]string `json:"names,omitempty"`
}

type Error Uses

type Error struct {
    Code string `json:"code,omitempty"`
    Err  string `json:"error,omitempty"`
}

func (Error) Error Uses

func (e Error) Error() string

type Location Uses

type Location struct {
    AccuracyRadius    int     `json:"accuracy_radius,omitempty"`
    AverageIncome     int     `json:"average_income,omitempty"`
    Latitude          float64 `json:"latitude,omitempty"`
    Longitude         float64 `json:"longitude,omitempty"`
    MetroCode         int     `json:"metro_code,omitempty"`
    PopulationDensity int     `json:"population_density,omitempty"`
    TimeZone          string  `json:"time_zone,omitempty"`
}

type MaxMind Uses

type MaxMind struct {
    QueriesRemaining int `json:"queries_remaining,omitempty"`
}

type Postal Uses

type Postal struct {
    Code       string `json:"code,omitempty"`
    Confidence int    `json:"confidence,omitempty"`
}

type RegisteredCountry Uses

type RegisteredCountry struct {
    GeoNameId int               `json:"geoname_id,omitempty"`
    IsoCode   string            `json:"iso_code,omitempty"`
    Names     map[string]string `json:"names,omitempty"`
}

type RepresentedCountry Uses

type RepresentedCountry struct {
    GeoNameId int               `json:"geoname_id,omitempty"`
    IsoCode   string            `json:"iso_code,omitempty"`
    Names     map[string]string `json:"names,omitempty"`
    Type      string            `json:"type,omitempty"`
}

type Response Uses

type Response struct {
    City               City               `json:"city,omitempty"`
    Continent          Continent          `json:"continent,omitempty"`
    Country            Country            `json:"country,omitempty"`
    Location           Location           `json:"location,omitempty"`
    Postal             Postal             `json:"postal,omitempty"`
    RegisteredCountry  RegisteredCountry  `json:"registered_country,omitempty"`
    RepresentedCountry RepresentedCountry `json:"represented_country,omitempty"`
    Subdivisions       []Subdivision      `json:"subdivisions,omitempty"`
    Traits             Traits             `json:"traits,omitempty"`
    MaxMind            MaxMind            `json:"maxmind,omitempty"`
}

type Subdivision Uses

type Subdivision struct {
    Confidence int               `json:"confidence,omitempty"`
    GeoNameId  int               `json:"geoname_id,omitempty"`
    IsoCode    string            `json:"iso_code,omitempty"`
    Names      map[string]string `json:"names,omitempty"`
}

type Traits Uses

type Traits struct {
    AutonomousSystemNumber       int    `json:"autonomous_system_number,omitempty"`
    AutonomousSystemOrganization string `json:"autonomous_system_organization,omitempty"`
    Domain                       string `json:"domain,omitempty"`
    IsAnonymousProxy             bool   `json:"is_anonymous_proxy,omitempty"`
    IsSatelliteProvider          bool   `json:"is_satellite_provider,omitempty"`
    Isp                          string `json:"isp,omitempty"`
    IpAddress                    string `json:"ip_address,omitempty"`
    Organization                 string `json:"organization,omitempty"`
    UserType                     string `json:"user_type,omitempty"`
}

Directories

PathSynopsis
example

Package geoip2 imports 4 packages (graph) and is imported by 6 packages. Updated 2017-04-12. Refresh now. Tools for package owners.