-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeolocate.go
More file actions
32 lines (24 loc) · 821 Bytes
/
geolocate.go
File metadata and controls
32 lines (24 loc) · 821 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
package main
import (
"fmt"
"github.com/go-resty/resty/v2"
"github.com/tidwall/gjson"
)
func geolocate(macAddressJson string, apiKey string)(lat string, lng string){
request := fmt.Sprintf("https://www.googleapis.com/geolocation/v1/geolocate?key=%s", apiKey)
rclient := resty.New()
resp,apierr := rclient.R().
SetHeader("Content-Type", "application/json").
SetBody(macAddressJson).
Post(request)
if apierr != nil {
fmt.Println("API Call Bombed")
fmt.Println(apierr)
}
location := string(resp.Body())
latJson := gjson.Get(location, "location.lat")
lat = latJson.String()
lngJson := gjson.Get(location, "location.lng")
lng = lngJson.String()
return
}