weather-cli/cmd/main.go
2022-08-02 23:26:28 -04:00

81 lines
1.5 KiB
Go

package main
import (
"log"
"os"
pb "codeberg.org/andcscott/weather-cli/proto"
"github.com/joho/godotenv"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
const version string = "0.2.0"
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"`
}
type Wind struct {
Speed float32 `json:"speed"`
Gust float32 `json:"gust"`
}
type Forecast struct {
//Overview weatherOverview `json:"weather"`
Main Weather `json:"main"`
Wind Wind `json:"wind"`
}
type Config struct {
Units string `json:"units"`
Location string `json:"loc"`
Longitude string `json:"lat"`
Latitude string `json:"lon"`
ApiKey string `json:"appid"`
}
type Application struct {
Forecast Forecast
Config Config
Version string
Client pb.RouteGuideClient
}
func main() {
conn, err := grpc.Dial("localhost:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalln(err)
}
defer conn.Close()
// Load .env
err = godotenv.Load()
if err != nil {
log.Fatalln(err)
}
// Read API_KEY from .env and create app
cfg := Config{
Units: "imperial",
ApiKey: os.Getenv("API_KEY"),
}
fcst := Forecast{}
app := Application{
Config: cfg,
Forecast: fcst,
Version: version,
Client: pb.NewRouteGuideClient(conn),
}
mainMenu(&app)
}