mirror of
https://codeberg.org/andyscott/weather-cli.git
synced 2024-11-12 06:30:49 -05:00
46 lines
722 B
Go
46 lines
722 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"io/ioutil"
|
||
|
"log"
|
||
|
"net/http"
|
||
|
"strings"
|
||
|
"sync"
|
||
|
)
|
||
|
|
||
|
func getLocation(wg *sync.WaitGroup, cfg *config) {
|
||
|
|
||
|
errMsg := "\nSorry, couldn't get your location automatically"
|
||
|
|
||
|
res, err := http.Get("https://ipinfo.io/json")
|
||
|
if err != nil {
|
||
|
fmt.Println(errMsg)
|
||
|
log.Println(err)
|
||
|
return
|
||
|
}
|
||
|
defer res.Body.Close()
|
||
|
|
||
|
body, err := ioutil.ReadAll(res.Body)
|
||
|
if err != nil {
|
||
|
fmt.Println(errMsg)
|
||
|
log.Panicln(err)
|
||
|
}
|
||
|
|
||
|
err = json.Unmarshal(body, &cfg)
|
||
|
if err != nil {
|
||
|
fmt.Println(errMsg)
|
||
|
log.Fatalln(err)
|
||
|
}
|
||
|
|
||
|
loc := strings.Split(cfg.Location, ",")
|
||
|
cfg.Latitude, cfg.Longitude = loc[0], loc[1]
|
||
|
|
||
|
wg.Done()
|
||
|
}
|
||
|
|
||
|
func getPreciseLocation(wg *sync.WaitGroup, cfg *config) {
|
||
|
|
||
|
}
|