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