-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampleGET.go
More file actions
43 lines (36 loc) · 884 Bytes
/
ExampleGET.go
File metadata and controls
43 lines (36 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"net/http"
"io/ioutil"
"encoding/json"
"fmt"
)
type OpenIPAPI_INFO struct {
IP string `json:"ip"`
Country string `json:"country"`
City string `json:"city"`
}
func main() {
ipAddress := "1.1.1.1"
url := fmt.Sprintf("https://openipapi.cloudshield.club/api?ip=%s", ipAddress)
response, err := http.Get(url)
if err != nil {
fmt.Println("Failed to make GET request:", err)
return
}
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Println("Failed to read response body:", err)
return
}
var OpenIPAPI_INFO OpenIPAPI_INFO
err = json.Unmarshal(body, &OpenIPAPI_INFO)
if err != nil {
fmt.Println("Failed to decode JSON response:", err)
return
}
fmt.Println("IP:", OpenIPAPI_INFO.IP)
fmt.Println("Country:", OpenIPAPI_INFO.Country)
fmt.Println("City:", OpenIPAPI_INFO.City)
}