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