mirror of
https://codeberg.org/andyscott/weather-cli.git
synced 2024-11-08 05:50:51 -05:00
Remove WaitGroup from application
This commit is contained in:
parent
c1a53b7e4b
commit
e68ede2c98
4 changed files with 15 additions and 29 deletions
|
@ -38,7 +38,8 @@ func advancedMenu(app *application) {
|
|||
fmt.Printf("\nChanged units from %s to %s...\n\n", current, app.Config.Units)
|
||||
} else if option == "2" {
|
||||
getPreciseLocation(app)
|
||||
getCurrent(app)
|
||||
printWeather(app)
|
||||
}
|
||||
}
|
||||
app.WaitGroup.Done()
|
||||
}
|
||||
|
|
|
@ -33,8 +33,6 @@ func getLocation(app *application) {
|
|||
|
||||
loc := strings.Split(app.Config.Location, ",")
|
||||
app.Config.Latitude, app.Config.Longitude = loc[0], loc[1]
|
||||
|
||||
app.WaitGroup.Done()
|
||||
}
|
||||
|
||||
func getPreciseLocation(app *application) {
|
||||
|
@ -55,5 +53,4 @@ func getPreciseLocation(app *application) {
|
|||
log.Println(err)
|
||||
}
|
||||
app.Config.Latitude = strings.TrimSuffix(input, "\n")
|
||||
//app.WaitGroup.Done()
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
@ -42,22 +41,21 @@ type config struct {
|
|||
}
|
||||
|
||||
type application struct {
|
||||
Forecast forecast
|
||||
Config config
|
||||
WaitGroup sync.WaitGroup
|
||||
Version string
|
||||
Forecast forecast
|
||||
Config config
|
||||
Version string
|
||||
}
|
||||
|
||||
func printWeather(app *application) {
|
||||
|
||||
var unitString string
|
||||
var unitStr string
|
||||
if app.Config.Units == "imperial" {
|
||||
unitString = "Farhenheit/mph"
|
||||
unitStr = "Farhenheit/mph"
|
||||
} else {
|
||||
unitString = "Celsius/kph"
|
||||
unitStr = "Celsius/kph"
|
||||
}
|
||||
|
||||
fmt.Printf("\nUnits: %s (%s)\n\n", app.Config.Units, unitString)
|
||||
fmt.Printf("\nUnits: %s (%s)\n\n", app.Config.Units, unitStr)
|
||||
fmt.Printf("Current temperature: %.2f\n", app.Forecast.Main.Temp)
|
||||
fmt.Printf("Feels like: %.2f\n", app.Forecast.Main.FeelsLike)
|
||||
fmt.Printf("High: %.2f\n", app.Forecast.Main.HighTemp)
|
||||
|
@ -82,13 +80,10 @@ func main() {
|
|||
|
||||
fcst := forecast{}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
||||
app := application{
|
||||
Config: cfg,
|
||||
Forecast: fcst,
|
||||
WaitGroup: wg,
|
||||
Version: version,
|
||||
Config: cfg,
|
||||
Forecast: fcst,
|
||||
Version: version,
|
||||
}
|
||||
|
||||
var option string
|
||||
|
@ -114,17 +109,11 @@ func main() {
|
|||
option = strings.TrimSuffix(input, "\n")
|
||||
|
||||
if option == "1" || option == "" {
|
||||
app.WaitGroup.Add(1)
|
||||
go getLocation(&app)
|
||||
app.WaitGroup.Wait()
|
||||
app.WaitGroup.Add(1)
|
||||
go getCurrent(&app)
|
||||
app.WaitGroup.Wait()
|
||||
getLocation(&app)
|
||||
getCurrent(&app)
|
||||
printWeather(&app)
|
||||
} else if option == "2" {
|
||||
app.WaitGroup.Add(1)
|
||||
go advancedMenu(&app)
|
||||
app.WaitGroup.Wait()
|
||||
advancedMenu(&app)
|
||||
} else if option == "0" {
|
||||
return
|
||||
} else {
|
||||
|
|
|
@ -30,5 +30,4 @@ func getCurrent(app *application) {
|
|||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
app.WaitGroup.Done()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue