IP Location in Go
Find the location of an IP address in Go programming language (golang) !
Try it out live
Code Snippet
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
)
func main() {
ipapiClient := http.Client{}
req, err := http.NewRequest("GET", "https://ipapi.co/json/", nil)
if err != nil {
log.Fatal(err)
}
req.Header.Set("User-Agent", "ipapi.co/#go-v1.3")
resp, err := ipapiClient.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(body))
}