weather-cli/cmd/main.go

89 lines
1.5 KiB
Go
Raw 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-07-27 14:55:38 -04:00
const version string = "0.2.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 {
//Overview weatherOverview `json:"weather"`
2022-08-02 23:26:28 -04:00
Main Weather `json:"main"`
Wind Wind `json:"wind"`
}
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 {
Forecast Forecast
Config Config
2022-07-09 15:33:10 -04:00
Version string
2022-08-02 22:16:38 -04:00
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-02 23:26:28 -04:00
app := Application{
2022-07-09 15:33:10 -04:00
Config: cfg,
Forecast: fcst,
Version: version,
2022-08-02 22:16:38 -04:00
Client: pb.NewRouteGuideClient(conn),
}
2022-08-02 22:16:38 -04:00
mainMenu(&app)
}