mirror of
https://codeberg.org/andyscott/weather-cli.git
synced 2024-12-21 12:43:09 -05:00
Prompt for longitude and latitude
This commit is contained in:
parent
12012b54a6
commit
51ffa88fe9
1 changed files with 27 additions and 7 deletions
|
@ -1,18 +1,21 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func getLocation(wg *sync.WaitGroup, cfg *config) {
|
func getLocation(app *application) {
|
||||||
|
|
||||||
res, err := http.Get("https://ipinfo.io/json")
|
res, err := http.Get("https://ipinfo.io/json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println("Unable to automatically obtain location, please try again.")
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -23,17 +26,34 @@ func getLocation(wg *sync.WaitGroup, cfg *config) {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(body, &cfg)
|
err = json.Unmarshal(body, &app.Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
loc := strings.Split(cfg.Location, ",")
|
loc := strings.Split(app.Config.Location, ",")
|
||||||
cfg.Latitude, cfg.Longitude = loc[0], loc[1]
|
app.Config.Latitude, app.Config.Longitude = loc[0], loc[1]
|
||||||
|
|
||||||
wg.Done()
|
app.WaitGroup.Done()
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPreciseLocation(wg *sync.WaitGroup, cfg *config) {
|
func getPreciseLocation(app *application) {
|
||||||
|
|
||||||
|
fmt.Print("\nEnter longitude: ")
|
||||||
|
|
||||||
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
input, err := reader.ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
app.Config.Longitude = strings.TrimSuffix(input, "\n")
|
||||||
|
|
||||||
|
fmt.Print("\nEnter latitude: ")
|
||||||
|
|
||||||
|
input, err = reader.ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
app.Config.Latitude = strings.TrimSuffix(input, "\n")
|
||||||
|
//app.WaitGroup.Done()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue