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
Subtract N number of Year, Month, Day, Hour, Minute, Second, Millisecond, Microsecond and Nanosecond to current date-time.
How To Make HTTP Requests in Go?
How to declare empty Map in Go?
How to add and update elements in Map?
How to check if a string contains a numbers in Golang?
Golang HTTP GET request with parameters