goip

package module
v0.0.0-...-1cfa934 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2021 License: MIT Imports: 4 Imported by: 1

README

go-ip-api

A simple wrapper around the ip-api.com API for IP geolocation information written in Go (golang). Works for both the free API as well as the paid, commercial API if you have purchased a Pro license.

Usage

Import and create a new client.

import "github.com/jpiontek/go-ip-api"

client := goip.NewClient()

If you have an api key for a paid account then use

client := goip.NewClientWithApiKey("my-api-key")

Request your current public IP info.

result := client.GetLocation()

Or supply a specific IP address.

result := client.GetLocationForIp("127.0.0.1")

Keep in mind that the free account is limited to 150 requests per minute. If you exceed this limit your IP address is blacklisted from making further requests. To correct this visit this page.

##License

MIT © Jeremiah Piontek

Documentation

Overview

Package goip provides a thin wrapper around the ip-api.com API to retrieve geolocation data for a specific IP address

Index

Constants

View Source
const PRO_URI = "http://pro.ip-api.com/json/"

Pro URI

View Source
const STANDARD_URI = "http://ip-api.com/json/"

Primary URI

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	GetLocation() (*Location, error)
	GetLocationForIp(ip string) (*Location, error)
}

func NewClient

func NewClient() Client

NewClient returns a new client

func NewClientWithApiKey

func NewClientWithApiKey(apiKey string) Client

type Location

type Location struct {
	As          string  `json:"as"`
	City        string  `json:"city"`
	Country     string  `json:"country"`
	CountryCode string  `json:"countryCode"`
	Isp         string  `json:"isp"`
	Lat         float32 `json:"lat"`
	Lon         float32 `json:"lon"`
	Org         string  `json:"org"`
	Query       string  `json:"query"`
	Region      string  `json:"region"`
	RegionName  string  `json:"regionName"`
	Status      string  `json:"status"`
	Timezone    string  `json:"timezone"`
	Zip         string  `json:"zip"`
}

Location contains all the relevant data for an IP

func (*Location) Close

func (g *Location) Close()

type ProClient

type ProClient struct {
	URI        string
	HttpClient *http.Client
	ApiKey     string
}

ProClient is a commercial client for retrieving location data.

func (*ProClient) GetLocation

func (g *ProClient) GetLocation() (*Location, error)

GetLocation retrieves the current client's public IP address location information

func (*ProClient) GetLocationForIp

func (g *ProClient) GetLocationForIp(ip string) (*Location, error)

GetLocationForIp retrieves the supplied IP address's location information

type StandardClient

type StandardClient struct {
	URI        string
	HttpClient *http.Client
}

StandardClient is a free client for retreiving location data with a 150 request per minute limit.

func (*StandardClient) GetLocation

func (g *StandardClient) GetLocation() (*Location, error)

GetLocation retrieves the current client's public IP address location information

func (*StandardClient) GetLocationForIp

func (g *StandardClient) GetLocationForIp(ip string) (*Location, error)

GetLocationForIp retrieves the supplied IP address's location information

Jump to

Keyboard shortcuts

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