ipifyorg

package
v1.0.2 Latest Latest
Warning

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

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

Documentation

Overview

Package ipifyorg implements an interface to the ipify.org API.

- Limits of the ipify.org API: 1000 request/day or 50,000 requests/month for free plan.

Index

Constants

This section is empty.

Variables

View Source
var IOReadAll = io.ReadAll

IOReadAll is a copy of io.ReadAll function to ease mock it's behavior during test.

View Source
var LogInfo = info.Log

LogInfo is a copy of info.Log function to ease mock it's behavior during test.

Functions

This section is empty.

Types

type Client

type Client struct {
	EndpointURL string
}

Client holds information to request ipify.org API.

func New

func New() *Client

New returns a new Client for the ipify.org API with default values.

func (*Client) GetIP

func (c *Client) GetIP() (net.IP, error)

GetIP returns the current IP address detected by ipify.org.

func (*Client) Name

func (c *Client) Name() string

Name returns the URL of the current provider as its name.

func (*Client) SetURL

func (c *Client) SetURL(url string)

SetURL overrides the default value of the API endpoint URL.

type Response

type Response struct {
	Provider     string `json:"provider"`
	IP           string `json:"ip"`
	HostName     string `json:"hostname,omitempty"`
	City         string `json:"city,omitempty"`
	Region       string `json:"region,omitempty"`
	Location     string `json:"loc,omitempty"`
	Organization string `json:"org,omitempty"`
	PostalCode   string `json:"postal,omitempty"`
	TimeZone     string `json:"timezone,omitempty"`
	Readme       string `json:"readme,omitempty"`
}

Response is the structure of JSON from the API response of ipify.org.

func (*Response) String

func (r *Response) String() string

String returns the struct pretty in JSON format.

Jump to

Keyboard shortcuts

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