iplookup

package
v0.0.0-...-f94be1b Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 12 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-lookup service. A request to ip-lookup service is made only when the information is not available in the cache.

type IPLookup

type IPLookup struct {
	BusinessName    string `json:"businessName"`
	BusinessWebsite string `json:"businessWebsite"`
	City            string `json:"city"`
	Continent       string `json:"continent"`
	Country         string `json:"country"`
	CountryCode     string `json:"countryCode"`
	IPName          string `json:"ipName"`
	IPType          string `json:"ipType"`
	ISP             string `json:"isp"`
	Lat             string `json:"lat"`
	Lon             string `json:"lon"`
	Org             string `json:"org"`
	Query           string `json:"query"`
	Region          string `json:"region"`
	Status          string `json:"status"`
}

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

type Info

type Info int

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

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

Information fetched from an IP address.

Jump to

Keyboard shortcuts

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