ip

package
v3.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2022 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTimeout = 10 * time.Second

Variables

View Source
var IPGetters = []IPGetter{
	{
		ServiceURL: "https://httpbin.org/ip",
		GetIP: func(url string, ctx context.Context) (string, error) {
			s, err := HTTPJSONGetField("origin")(url, ctx)
			if err != nil {
				return "", err
			}
			return strings.Split(s, ", ")[0], nil
		},
	},
	{
		ServiceURL: "https://api.myip.com",
		GetIP:      HTTPJSONGetField("ip"),
	},
	{
		ServiceURL: "https://ip4.seeip.org/json",
		GetIP:      HTTPJSONGetField("ip"),
	},
	{
		ServiceURL: "https://ipv4bot.whatismyipaddress.com/",
		GetIP:      HTTPGetString,
	},
	{
		ServiceURL: "https://api.ipify.org?format=json",
		GetIP:      HTTPJSONGetField("ip"),
	},
}

Functions

func HTTPGetBody

func HTTPGetBody(url string, ctx context.Context) ([]byte, error)

func HTTPGetString

func HTTPGetString(url string, ctx context.Context) (string, error)

func HTTPJSONGetField

func HTTPJSONGetField(field string) func(string, context.Context) (string, error)

func RunProviders

func RunProviders(ipGetters []IPGetter, timeout time.Duration) (string, error)

Types

type IPGetter

type IPGetter struct {
	ServiceURL string
	GetIP      func(url string, ctx context.Context) (string, error)
}

Jump to

Keyboard shortcuts

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