Skip to content

Instantly share code, notes, and snippets.

@se7enack
Last active November 14, 2024 23:24
Show Gist options
  • Save se7enack/20df7be2c27f6e0ec476705e8d20e647 to your computer and use it in GitHub Desktop.
Save se7enack/20df7be2c27f6e0ec476705e8d20e647 to your computer and use it in GitHub Desktop.
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