-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
45 lines (36 loc) · 932 Bytes
/
main.go
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
44
45
package main
import (
"encoding/xml"
"fmt"
)
func main() {
// instancing a request
request, err := NewSoapRequest()
if err != nil {
fmt.Println(err)
}
// set the request address, type and address
request.SetRequest("http://www.webservicex.net/geoipservice.asmx", "GetGeoIp", "8.8.8.8")
// run the request
byteBody, err := request.Do()
if err != nil {
fmt.Println(err)
}
// get the response
var response SoapGetGeoIpResponse
// unmarshal
err = xml.Unmarshal(byteBody, &response)
if err != nil {
fmt.Println(err)
}
// get the result object
getGeoIpResult := response.Body.GetGeoIPResponse.GetGeoIPResponseResult
// printing the output
if getGeoIpResult.ReturnCode == "1" {
fmt.Println(
fmt.Sprintf("Results for IP %s:\n", getGeoIpResult.IP),
fmt.Sprintf("\t- Country:\t %s \n", getGeoIpResult.CountryName),
fmt.Sprintf("\t- Country Code:\t %s \n", getGeoIpResult.CountryCode),
)
}
}