weather-cli/cmd/main.go

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 weatherMain 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 weatherWind struct {
Speed float32 `json:"speed"`
Gust float32 `json:"gust"`
}
type forecast struct {
//Overview weatherOverview `json:"weather"`
Main weatherMain `json:"main"`
Wind weatherWind `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)
}