mirror of
https://codeberg.org/andyscott/weather-cli.git
synced 2024-12-21 12:43:09 -05:00
Structs updated
This commit is contained in:
parent
e74d4fe74f
commit
0e88ed0445
5 changed files with 17 additions and 17 deletions
|
@ -12,7 +12,7 @@ import (
|
|||
)
|
||||
|
||||
// Use WAN address to obtain location data
|
||||
func getLocation(app *application) {
|
||||
func getLocation(app *Application) {
|
||||
|
||||
res, err := http.Get("https://ipinfo.io/json")
|
||||
if err != nil {
|
||||
|
@ -37,7 +37,7 @@ func getLocation(app *application) {
|
|||
}
|
||||
|
||||
// Prompt user for location
|
||||
func getPreciseLocation(app *application) {
|
||||
func getPreciseLocation(app *Application) {
|
||||
|
||||
fmt.Print("\nEnter latitude: ")
|
||||
|
||||
|
|
24
cmd/main.go
24
cmd/main.go
|
@ -12,7 +12,7 @@ import (
|
|||
|
||||
const version string = "0.2.0"
|
||||
|
||||
type weatherMain struct {
|
||||
type Weather struct {
|
||||
Temp float32 `json:"temp"`
|
||||
FeelsLike float32 `json:"feels_like"`
|
||||
HighTemp float32 `json:"temp_max"`
|
||||
|
@ -21,18 +21,18 @@ type weatherMain struct {
|
|||
Humidity uint `json:"humidity"`
|
||||
}
|
||||
|
||||
type weatherWind struct {
|
||||
type Wind struct {
|
||||
Speed float32 `json:"speed"`
|
||||
Gust float32 `json:"gust"`
|
||||
}
|
||||
|
||||
type forecast struct {
|
||||
type Forecast struct {
|
||||
//Overview weatherOverview `json:"weather"`
|
||||
Main weatherMain `json:"main"`
|
||||
Wind weatherWind `json:"wind"`
|
||||
Main Weather `json:"main"`
|
||||
Wind Wind `json:"wind"`
|
||||
}
|
||||
|
||||
type config struct {
|
||||
type Config struct {
|
||||
Units string `json:"units"`
|
||||
Location string `json:"loc"`
|
||||
Longitude string `json:"lat"`
|
||||
|
@ -40,9 +40,9 @@ type config struct {
|
|||
ApiKey string `json:"appid"`
|
||||
}
|
||||
|
||||
type application struct {
|
||||
Forecast forecast
|
||||
Config config
|
||||
type Application struct {
|
||||
Forecast Forecast
|
||||
Config Config
|
||||
Version string
|
||||
Client pb.RouteGuideClient
|
||||
}
|
||||
|
@ -62,14 +62,14 @@ func main() {
|
|||
}
|
||||
|
||||
// Read API_KEY from .env and create app
|
||||
cfg := config{
|
||||
cfg := Config{
|
||||
Units: "imperial",
|
||||
ApiKey: os.Getenv("API_KEY"),
|
||||
}
|
||||
|
||||
fcst := forecast{}
|
||||
fcst := Forecast{}
|
||||
|
||||
app := application{
|
||||
app := Application{
|
||||
Config: cfg,
|
||||
Forecast: fcst,
|
||||
Version: version,
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
func mainMenu(app *application) {
|
||||
func mainMenu(app *Application) {
|
||||
|
||||
// Display main menu
|
||||
fmt.Println("\n=====================================================")
|
||||
|
|
|
@ -3,7 +3,7 @@ package main
|
|||
import "fmt"
|
||||
|
||||
// Prints saved weather data to the terminal
|
||||
func printWeather(app *application) {
|
||||
func printWeather(app *Application) {
|
||||
|
||||
var unitStr string
|
||||
if app.Config.Units == "imperial" {
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
)
|
||||
|
||||
// Get and store the current forecast
|
||||
func getCurrent(app *application) {
|
||||
func getCurrent(app *Application) {
|
||||
|
||||
lat := "lat=" + app.Config.Latitude
|
||||
lon := "&lon=" + app.Config.Longitude
|
||||
|
|
Loading…
Reference in a new issue