Remove WaitGroup from application

This commit is contained in:
Andrew Scott 2022-07-09 15:33:10 -04:00
parent c1a53b7e4b
commit e68ede2c98
Signed by: a
GPG key ID: 3EB62D0BBB8DB381
4 changed files with 15 additions and 29 deletions

View file

@ -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()
}

View file

@ -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()
}

View file

@ -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 {

View file

@ -30,5 +30,4 @@ func getCurrent(app *application) {
if err != nil {
log.Println(err)
}
app.WaitGroup.Done()
}