weather-cli/cmd/client/location.go

40 lines
585 B
Go
Raw Normal View History

2022-07-07 23:43:16 -04:00
package main
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
"strings"
"sync"
)
func getLocation(wg *sync.WaitGroup, cfg *config) {
res, err := http.Get("https://ipinfo.io/json")
if err != nil {
log.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
2022-07-08 04:01:38 -04:00
log.Println(err)
2022-07-07 23:43:16 -04:00
}
err = json.Unmarshal(body, &cfg)
if err != nil {
2022-07-08 04:01:38 -04:00
log.Println(err)
2022-07-07 23:43:16 -04:00
}
loc := strings.Split(cfg.Location, ",")
cfg.Latitude, cfg.Longitude = loc[0], loc[1]
wg.Done()
}
func getPreciseLocation(wg *sync.WaitGroup, cfg *config) {
}