How to get current IP form ipify.org ?
Example
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
url := "https://api.ipify.org?format=text"
fmt.Printf("Getting IP address from ipify\n")
resp, err := http.Get(url)
if err != nil {
panic(err)
}
defer resp.Body.Close()
ip, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Printf("My IP is:%s\n", ip)
}
Output
Getting IP address from ipify
My IP is:49.34.146.212
Most Helpful This Week
URL parser in Golang
How to handle HTTP Get response?
How to create thumbnail of an image?
Print index and element or data from Array, Slice and Map
Example Function that takes an interface type as value and pointer?
Example: Split, Join, and Equal from BYTES Package
How to check if a string contains a white space in Golang?
Regular expression to validate email address
What is GOPATH?
Different ways for Integer to String Conversions