ipapi

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// GetLocation gets the location for the given IP address or the
	// IP of the server if blank.
	GetLocation(ctx context.Context, ip string) (*WorldLocation, error)
	// Name provides a client name used to report health check issues.
	Name() string
	// Ping checks the client is healthy.
	Ping(ctx context.Context) error
}

Client is the ipapi client interface. It implements a simple in-memory transparent cache to avoid hitting the API too often and getting throttled (429).

func New

func New(c *http.Client) Client

New returns a new client for the ipapi.co API.

type GetLocationFunc

type GetLocationFunc func(ctx context.Context, ip string) (*WorldLocation, error)

GetLocationFunc mocks the GetLocation method.

type Mock

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

Mock implementation of the ipapi client.

func NewMock

func NewMock(t *testing.T) *Mock

NewMock returns a new mock client.

func (*Mock) AddGetLocationFunc

func (m *Mock) AddGetLocationFunc(f GetLocationFunc)

AddGetLocationFunc adds f to the mocked call sequence.

func (*Mock) GetLocation

func (m *Mock) GetLocation(ctx context.Context, ip string) (*WorldLocation, error)

GetLocation implements the Client interface.

func (*Mock) HasMore

func (m *Mock) HasMore() bool

HasMore returns true if there are more calls to be made.

func (*Mock) Name

func (m *Mock) Name() string

Mock health-check implementation.

func (*Mock) Ping

func (m *Mock) Ping(ctx context.Context) error

func (*Mock) SetGetLocationFunc

func (m *Mock) SetGetLocationFunc(f GetLocationFunc)

SetGetLocationFunc sets f for all calls to the mocked method.

type WorldLocation

type WorldLocation struct {
	// Lat is the latitude of the location.
	Lat float64 `json:"lat"`
	// Long is the longitude of the location.
	Long float64 `json:"lon"`
	// City is the city of the location.
	City string `json:"city"`
	// Region is the region/state of the location.
	Region string `json:"region"`
	// Country is the country of the location.
	Country string `json:"country"`
}

WorldLocation represents the geographical location of an IP address.

Jump to

Keyboard shortcuts

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