2022-07-07 20:27:00 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
2022-07-08 22:14:35 -04:00
|
|
|
|
2022-08-02 22:16:38 -04:00
|
|
|
pb "codeberg.org/andcscott/weather-cli/proto"
|
2022-07-08 22:14:35 -04:00
|
|
|
"github.com/joho/godotenv"
|
2022-08-02 22:16:38 -04:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc/credentials/insecure"
|
2022-07-07 20:27:00 -04:00
|
|
|
)
|
|
|
|
|
2022-08-08 04:33:45 -04:00
|
|
|
const version string = "1.0.0"
|
2022-07-08 22:14:35 -04:00
|
|
|
|
2022-08-02 23:26:28 -04:00
|
|
|
type Weather struct {
|
2022-07-08 22:14:35 -04:00
|
|
|
Temp float32 `json:"temp"`
|
|
|
|
FeelsLike float32 `json:"feels_like"`
|
|
|
|
HighTemp float32 `json:"temp_max"`
|
|
|
|
LowTemp float32 `json:"temp_min"`
|
|
|
|
Pressure uint `json:"pressure"`
|
|
|
|
Humidity uint `json:"humidity"`
|
|
|
|
}
|
|
|
|
|
2022-08-02 23:26:28 -04:00
|
|
|
type Wind struct {
|
2022-07-08 22:14:35 -04:00
|
|
|
Speed float32 `json:"speed"`
|
|
|
|
Gust float32 `json:"gust"`
|
|
|
|
}
|
|
|
|
|
2022-08-02 23:26:28 -04:00
|
|
|
type Forecast struct {
|
2022-08-06 22:16:56 -04:00
|
|
|
Weather Weather `json:"main"`
|
|
|
|
Wind Wind `json:"wind"`
|
2022-07-08 22:14:35 -04:00
|
|
|
}
|
|
|
|
|
2022-08-08 03:50:24 -04:00
|
|
|
type HistoricalForecast struct {
|
|
|
|
Temp float32 `json:"temp"`
|
|
|
|
FeelsLike float32 `json:"feels_like"`
|
|
|
|
Pressure uint `json:"pressure"`
|
|
|
|
Humidity uint `json:"humidity"`
|
|
|
|
Speed float32 `json:"wind_speed"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type HistoricalData struct {
|
|
|
|
HistoricalForecast []HistoricalForecast `json:"data"`
|
|
|
|
}
|
|
|
|
|
2022-08-02 23:40:40 -04:00
|
|
|
type Date struct {
|
|
|
|
Year int32
|
|
|
|
Month int32
|
|
|
|
Day int32
|
|
|
|
}
|
|
|
|
|
2022-08-02 23:26:28 -04:00
|
|
|
type Config struct {
|
2022-08-09 01:13:22 -04:00
|
|
|
Units string
|
2022-07-07 23:43:16 -04:00
|
|
|
Location string `json:"loc"`
|
|
|
|
Longitude string `json:"lat"`
|
|
|
|
Latitude string `json:"lon"`
|
2022-08-02 23:40:40 -04:00
|
|
|
Date Date
|
2022-08-09 01:13:22 -04:00
|
|
|
ApiKey string
|
2022-07-08 22:14:35 -04:00
|
|
|
}
|
|
|
|
|
2022-08-02 23:26:28 -04:00
|
|
|
type Application struct {
|
2022-08-06 22:16:56 -04:00
|
|
|
Forecast Forecast
|
|
|
|
HistoricalForecast HistoricalForecast
|
|
|
|
Config Config
|
|
|
|
Version string
|
|
|
|
Client pb.RouteGuideClient
|
2022-07-08 22:14:35 -04:00
|
|
|
}
|
|
|
|
|
2022-07-07 20:27:00 -04:00
|
|
|
func main() {
|
|
|
|
|
2022-08-02 22:16:38 -04:00
|
|
|
conn, err := grpc.Dial("localhost:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
defer conn.Close()
|
|
|
|
|
2022-07-26 22:21:35 -04:00
|
|
|
// Load .env
|
2022-08-02 22:16:38 -04:00
|
|
|
err = godotenv.Load()
|
2022-07-08 22:14:35 -04:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
2022-07-26 22:21:35 -04:00
|
|
|
// Read API_KEY from .env and create app
|
2022-08-02 23:26:28 -04:00
|
|
|
cfg := Config{
|
2022-07-08 22:14:35 -04:00
|
|
|
Units: "imperial",
|
|
|
|
ApiKey: os.Getenv("API_KEY"),
|
2022-07-07 23:43:16 -04:00
|
|
|
}
|
|
|
|
|
2022-08-02 23:26:28 -04:00
|
|
|
fcst := Forecast{}
|
2022-08-06 22:16:56 -04:00
|
|
|
hFcst := HistoricalForecast{}
|
|
|
|
fcst.Weather.Temp = -500.00
|
|
|
|
hFcst.Temp = -500.00
|
2022-07-08 22:14:35 -04:00
|
|
|
|
2022-08-02 23:26:28 -04:00
|
|
|
app := Application{
|
2022-08-06 22:16:56 -04:00
|
|
|
Config: cfg,
|
|
|
|
Forecast: fcst,
|
|
|
|
HistoricalForecast: hFcst,
|
|
|
|
Version: version,
|
|
|
|
Client: pb.NewRouteGuideClient(conn),
|
2022-07-08 22:14:35 -04:00
|
|
|
}
|
2022-08-02 22:16:38 -04:00
|
|
|
mainMenu(&app)
|
2022-07-07 20:27:00 -04:00
|
|
|
}
|