22 lines
335 B
Go
22 lines
335 B
Go
|
package command
|
||
|
|
||
|
import (
|
||
|
"io/ioutil"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
func GetPublicIp() (str string, err error) {
|
||
|
url := "https://api.ipify.org?format=text"
|
||
|
resp, err := http.Get(url)
|
||
|
if err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
|
||
|
defer resp.Body.Close()
|
||
|
ip, err := ioutil.ReadAll(resp.Body)
|
||
|
if err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
|
||
|
return string(ip), nil
|
||
|
}
|