whatismyipcom

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: 9 Imported by: 0

Documentation

Overview

Package whatismyipcom provides an interface to the www.whatismyip.com web service.

Currently it is disabled in the command due to the following issue:

Index

Examples

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.

NewDocument is a copy of goquery.NewDocumentFromReader function to ease mock it's behavior during test.

Functions

func IsIPv4

func IsIPv4(ip string) bool

IsIPv4 returns true if the ip is well formatted.

func ScrapeIPv4

func ScrapeIPv4(html string) string

ScrapeIPv4 returns the first IPv4 address found from the given html.

Types

type Client

type Client struct {
	EndpointURL string
}

Client holds information to request www.whatismyip.com's URL.

func New

func New() *Client

New returns a new Client for the www.whatismyip.com with default values.

func (*Client) GetIP

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

GetIP returns the current IP address detected by www.whatismyip.com.

func (*Client) Name

func (c *Client) Name() string

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

Example
package main

import (
	"fmt"

	"github.com/KEINOS/whereami/pkg/provider/providers/whatismyipcom"
)

func main() {
	cli := whatismyipcom.New()

	fmt.Println(cli.Name())

}
Output:

https://www.whatismyip.com/

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"`
}

Response is the structure of JSON to hold info from www.whatismyip.com.

func GetResponse

func GetResponse(urlProvider string) (*Response, error)

GetResponse returns the Response object parsed from the www.whatismyip.com's content body.

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