location

package
v2.6.5 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IPAPICOMResolver

type IPAPICOMResolver struct {
}

IPAPICOMResolver is an IP address resolver based on the ip-api.com service.

func NewIPAPICOMResolver

func NewIPAPICOMResolver() *IPAPICOMResolver

NewIPAPICOMResolver returns an IP address resolver based on the ip-api.com service.

func (*IPAPICOMResolver) Name

func (i *IPAPICOMResolver) Name() string

Name returns the resolver name.

func (*IPAPICOMResolver) Resolve

func (i *IPAPICOMResolver) Resolve(ctx context.Context, ip string) (*Result, error)

Resolve resolves the geolocation of ip.

type IPAPICOResolver

type IPAPICOResolver struct {
}

IPAPICOResolver is an IP address resolver based on the ipapi.co service.

func NewIPAPICOResolver

func NewIPAPICOResolver() *IPAPICOResolver

NewIPAPICOResolver returns an IP address resolver based on the ipapi.co service.

func (*IPAPICOResolver) Name

func (i *IPAPICOResolver) Name() string

Name returns the resolver name.

func (*IPAPICOResolver) Resolve

func (i *IPAPICOResolver) Resolve(ctx context.Context, ip string) (*Result, error)

Resolve resolves the geolocation of ip.

type IPWHOISResolver

type IPWHOISResolver struct {
}

IPWHOISResolver is an IP address resolver based on the ipwho.is service.

func NewIPWHOISResolver

func NewIPWHOISResolver() *IPWHOISResolver

NewIPWHOISResolver returns an IP address resolver based on the ipwho.is service.

func (*IPWHOISResolver) Name

func (i *IPWHOISResolver) Name() string

Name returns the resolver name.

func (*IPWHOISResolver) Resolve

func (i *IPWHOISResolver) Resolve(ctx context.Context, ip string) (*Result, error)

Resolve resolves the geolocation of ip.

type Location

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

Location is a geolocation resolver that runs several resolvers concurrently to resolve an IP address.

func NewLocation

func NewLocation(resolvers ...Resolver) *Location

NewLocation returns a new Location backed by the given resolvers.

func (*Location) Parse

func (l *Location) Parse(ctx context.Context, ip string) (*Result, error)

Parse resolves the geolocation information of ip.

It returns as soon as one resolver succeeds, or an error when every resolver fails or ctx is done.

type Resolver

type Resolver interface {
	// Name returns the resolver name.
	Name() string
	// Resolve resolves the geolocation of ip.
	Resolve(ctx context.Context, ip string) (*Result, error)
}

Resolver is the IP address resolver interface.

type Result

type Result struct {
	IP       string `json:"ip"`       // IP address
	Country  string `json:"country"`  // Country
	Province string `json:"province"` // Province, autonomous region or municipality
	City     string `json:"city"`     // City
	ISP      string `json:"isp"`      // ISP
}

Result is the geolocation result of an IP address.

Jump to

Keyboard shortcuts

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