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 MAX_TRIES = 3
The maximum amount of tries to attempt when making API calls.
const VERSION = "1.0.0"
The version of this library.
Variables ¶
var API_URI = "https://api.ipify.org"
This is the ipify service base URI. This is where all API requests go.
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.
Usage:
package main import ( "fmt" "github.com/rdegges/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.