master
Buddy Sandidge 8 years ago
parent a747567d84
commit a63f9d657e

3
.gitignore vendored

@ -1,3 +1,5 @@
update-dns
# ---> Go
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
@ -23,4 +25,3 @@ _testmain.go
*.exe
*.test
*.prof

@ -0,0 +1,34 @@
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
)
func main() {
result, err := getIP("https://whatismyipv6.buddy.wtf/json")
if err != nil {
log.Fatal(err)
}
fmt.Println(result.IP)
}
type whatIsMyIPResult struct {
IP string `json:ip`
Version string `json:version`
}
func getIP(url string) (*whatIsMyIPResult, error) {
result, err := http.Get(url)
if err != nil {
return nil, err
}
defer result.Body.Close()
ipResult := &whatIsMyIPResult{}
if err := json.NewDecoder(result.Body).Decode(ipResult); err != nil {
return nil, err
}
return ipResult, nil
}
Loading…
Cancel
Save