weather-cli/cmd/main.go

105 lines
2 KiB
Go
Raw Permalink Normal View History

package main
import (
"log"
"os"
2022-08-02 22:16:38 -04:00
pb "codeberg.org/andcscott/weather-cli/proto"
"github.com/joho/godotenv"
2022-08-02 22:16:38 -04:00
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
2022-08-08 04:33:45 -04:00
const version string = "1.0.0"
2022-08-02 23:26:28 -04:00
type Weather struct {
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 {
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"`
}
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-07-07 23:43:16 -04:00
Units string `json:"units"`
Location string `json:"loc"`
Longitude string `json:"lat"`
Latitude string `json:"lon"`
2022-08-02 23:40:40 -04:00
Date Date
ApiKey string `json:"appid"`
}
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
}
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()
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{
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-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-08-02 22:16:38 -04:00
mainMenu(&app)
}