iplookup

package
v0.0.0-...-0fffe9f Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromRequest

func FromRequest(r *http.Request) string

FromRequest identifies the remote ip from an http request

Types

type IPInfo

type IPInfo struct {
	sync.Mutex
	// contains filtered or unexported fields
}

IPInfo maintains a cache to hold IpLookup information to avoid redundant network requests made for the same IP address.

func Instance

func Instance() *IPInfo

Instance returns the singleton instance of IPInfo.

func (*IPInfo) Cache

func (info *IPInfo) Cache(ip string, ipLookup *IPLookup)

Cache stores the IP information i.e. IPLookup in the cache.

func (*IPInfo) Cached

func (info *IPInfo) Cached(ipAddr string) (*IPLookup, bool)

Cached checks if the info for the ipAddr is present in the cache. If so we return the result from the cache itself.

func (*IPInfo) Get

func (info *IPInfo) Get(field Info, ip string) (string, error)

Get returns the specific field of information i.e. Info from IPLookup.

func (*IPInfo) GetCoordinates

func (info *IPInfo) GetCoordinates(ip string) (string, error)

GetCoordinates returns the formatted coordinates (both latitude and longitude) of the location fetched for IP.

func (*IPInfo) Lookup

func (info *IPInfo) Lookup(ip string) (*IPLookup, error)

Lookup fetches the IP information from the ip-api service.

type IPLookup

type IPLookup struct {
	City        string `json:"city"`
	Continent   string `json:"continent"`
	Country     string `json:"country"`
	CountryCode string `json:"countryCode"`
	ISP         string `json:"isp"`
	Lat         string `json:"lat"`
	Lon         string `json:"lon"`
	Org         string `json:"org"`
	Query       string `json:"query"`
	Region      string `json:"regionName"` // map to regionName provided by API
	Status      string `json:"status"`
}

IPLookup represents the response received from the ip-api service.

type Info

type Info int

Info is the information associated with an IP address provided by ip-api service.

const (
	// Removed: BusinessName, BusinessWebsite, IPName, IPType
	City Info = iota
	Continent
	Country
	CountryCode
	ISP
	Lat
	Lon
	Org
	Query
	Region
	Status
)

Updated information fetched from an IP address.

Jump to

Keyboard shortcuts

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