Last active
November 14, 2024 23:24
-
-
Save se7enack/20df7be2c27f6e0ec476705e8d20e647 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
) | |
var url = "https://ipv4ip.com/?format=json" | |
type Address struct { | |
Ip string `json:"ip"` | |
} | |
func main() { | |
resp, err := http.Get(url) | |
if err != nil { | |
fmt.Println("No response from request") | |
} | |
defer resp.Body.Close() | |
body, err := ioutil.ReadAll(resp.Body) | |
var jsonstr = body | |
var getIp Address | |
json.Unmarshal([]byte(jsonstr), &getIp) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println(getIp.Ip) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment