Documentation
¶
Overview ¶
Package ipify provides a single function for retrieving your computer's public IP address from the ipify service: http://www.ipify.org
Index ¶
Constants ¶
const API_URI_4 = "https://api.ipify.org"
This is the ipify service base URI for IPV4 resolution.
const API_URI_6 = "https://api6.ipify.org"
This is the ipify service base URI for IPV6 resolution.
const API_URI_64 = "https://api64.ipify.org"
This is the ipify service base URI for IPV4 or IPV6 resolution, whichever comes first.
const MAX_TRIES = 3
The maximum amount of tries to attempt when making API calls.
const VERSION = "2.0.2"
The version of this library.
Variables ¶
var USER_AGENT = fmt.Sprintf("go-ipify/%s go/%s %s", VERSION, runtime.Version()[2:], strings.Title(runtime.GOOS))
The user-agent string is provided so that I can (eventually) keep track of what libraries to support over time. EG: Maybe the service is used primarily by Windows developers, and I should invest more time in improving those integrations.
Functions ¶
func GetIp ¶
GetIp queries the ipify service (http://www.ipify.org) to retrieve this machine's public IP address. Returns your public IP address as a string, and any error encountered. By default, this function will run using exponential backoff -- if this function fails for any reason, the request will be retried up to 3 times.
This function will return either the IPV4 or IPV6 address, which ever resolves first.
Usage:
package main
import (
"fmt"
"github.com/tech10/go-ipify"
)
func main() {
ip, err := ipify.GetIp()
if err != nil {
fmt.Println("Couldn't get my IP address:", err)
} else {
fmt.Println("My IP address is:", ip)
}
}
Types ¶
This section is empty.