inetipinfo

package
v1.0.3 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 inetipinfo provides an interface to the inet-ip.info.

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 ipinfo.io API.

func New

func New() *Client

New returns a new Client for the inet-ip.info API with default values.

func (*Client) GetIP

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

GetIP returns the current IP address detected by inet-ip.info.

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"`
	IPAddress string `json:"ipAddress"`
	License   string `json:"license,omitempty"`
	ASN       struct {
		AutonomousSystemOrganization string `json:"AutonomousSystemOrganization,omitempty"`
		AutonomousSystemNumber       int    `json:"AutonomousSystemNumber,omitempty"`
	} `json:"asn,omitempty"`
	City struct {
		Postal struct {
			Code string `json:"Code,omitempty"`
		} `json:"Postal,omitempty"`
		Continent struct {
			Names struct {
				De   string `json:"de,omitempty"`
				En   string `json:"en,omitempty"`
				Es   string `json:"es,omitempty"`
				Fr   string `json:"fr,omitempty"`
				Ja   string `json:"ja,omitempty"`
				PtBR string `json:"pt-BR,omitempty"`
				Ru   string `json:"ru,omitempty"`
				ZhCN string `json:"zh-CN,omitempty"`
			} `json:"Names,omitempty"`
			Code      string `json:"Code,omitempty"`
			GeoNameID int    `json:"GeoNameID,omitempty"`
		} `json:"Continent,omitempty"`
		City struct {
			Names struct {
				De   string `json:"de,omitempty"`
				En   string `json:"en,omitempty"`
				Es   string `json:"es,omitempty"`
				Fr   string `json:"fr,omitempty"`
				Ja   string `json:"ja,omitempty"`
				PtBR string `json:"pt-BR,omitempty"`
				Ru   string `json:"ru,omitempty"`
				ZhCN string `json:"zh-CN,omitempty"`
			} `json:"Names,omitempty"`
			GeoNameID int `json:"GeoNameID,omitempty"`
		} `json:"City,omitempty"`
		Subdivisions []struct {
			IsoCode string `json:"IsoCode,omitempty"`
			Names   struct {
				De string `json:"de,omitempty"`
				En string `json:"en,omitempty"`
				Es string `json:"es,omitempty"`
				Fr string `json:"fr,omitempty"`
				Ja string `json:"ja,omitempty"`
				Ru string `json:"ru,omitempty"`
			} `json:"Names,omitempty"`
			GeoNameID int `json:"GeoNameID,omitempty"`
		} `json:"Subdivisions,omitempty"`
		Country struct {
			Names struct {
				De   string `json:"de,omitempty"`
				En   string `json:"en,omitempty"`
				Es   string `json:"es,omitempty"`
				Fr   string `json:"fr,omitempty"`
				Ja   string `json:"ja,omitempty"`
				PtBR string `json:"pt-BR,omitempty"`
				Ru   string `json:"ru,omitempty"`
				ZhCN string `json:"zh-CN,omitempty"`
			} `json:"Names,omitempty"`
			IsoCode           string `json:"IsoCode,omitempty"`
			GeoNameID         int    `json:"GeoNameID,omitempty"`
			IsInEuropeanUnion bool   `json:"IsInEuropeanUnion,omitempty"`
		} `json:"Country,omitempty"`
		RegisteredCountry struct {
			Names struct {
				De   string `json:"de,omitempty"`
				En   string `json:"en,omitempty"`
				Es   string `json:"es,omitempty"`
				Fr   string `json:"fr,omitempty"`
				Ja   string `json:"ja,omitempty"`
				PtBR string `json:"pt-BR,omitempty"`
				Ru   string `json:"ru,omitempty"`
				ZhCN string `json:"zh-CN,omitempty"`
			} `json:"Names,omitempty"`
			IsoCode           string `json:"IsoCode,omitempty"`
			GeoNameID         int    `json:"GeoNameID,omitempty"`
			IsInEuropeanUnion bool   `json:"IsInEuropeanUnion,omitempty"`
		} `json:"RegisteredCountry,omitempty"`
		RepresentedCountry struct {
			Names             interface{} `json:"Names,omitempty"`
			Type              string      `json:"Type,omitempty"`
			IsoCode           string      `json:"IsoCode,omitempty"`
			GeoNameID         int         `json:"GeoNameID,omitempty"`
			IsInEuropeanUnion bool        `json:"IsInEuropeanUnion,omitempty"`
		} `json:"RepresentedCountry,omitempty"`
		Location struct {
			TimeZone       string  `json:"TimeZone,omitempty"`
			Latitude       float64 `json:"Latitude,omitempty"`
			Longitude      float64 `json:"Longitude,omitempty"`
			AccuracyRadius int     `json:"AccuracyRadius,omitempty"`
			MetroCode      int     `json:"MetroCode,omitempty"`
		} `json:"Location,omitempty"`
		Traits struct {
			IsAnonymousProxy    bool `json:"IsAnonymousProxy,omitempty"`
			IsSatelliteProvider bool `json:"IsSatelliteProvider,omitempty"`
		} `json:"Traits,omitempty"`
	} `json:"city,omitempty"`
}

Response is the structure of JSON from the API response of inet-ip.info.

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