weather-cli/cmd/main.go

82 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"
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"`
}
2022-07-07 23:43:16 -04:00
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 {
2022-07-09 15:33:10 -04:00
Forecast forecast
Config config
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-07-07 23:43:16 -04:00
cfg := config{
Units: "imperial",
ApiKey: os.Getenv("API_KEY"),
2022-07-07 23:43:16 -04:00
}
fcst := forecast{}
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)
}