humiditycalc/main.go

57 lines
1.0 KiB
Go
Raw Normal View History

2024-10-26 14:31:51 +00:00
package main
import (
2024-11-02 12:24:36 +00:00
"fmt"
"os"
"strings"
2024-10-26 14:31:51 +00:00
"github.com/LeRoid-hub/humiditycalc/server"
2024-11-02 12:24:36 +00:00
"github.com/joho/godotenv"
2024-10-26 14:31:51 +00:00
)
func main() {
2024-11-02 12:24:36 +00:00
env := loadEnv()
if val, ok := env["MODE"]; ok {
if strings.ToLower(val) == "both" {
checkEnv(env)
server.Run(env)
2024-11-02 12:24:36 +00:00
} else if strings.ToLower(val) == "weather" {
checkEnv(env)
// weather.Run()
} else if strings.ToLower(val) == "calc" {
// calc.Run()
server.Run(env)
2024-11-02 12:24:36 +00:00
}
} else {
// calc.Run()
server.Run(env)
2024-11-02 12:24:36 +00:00
}
}
func loadEnv() map[string]string {
var env map[string]string
env, err := godotenv.Read()
if err != nil {
fmt.Println("Error loading .env file: ", err)
os.Exit(1)
}
if len(env) == 0 {
fmt.Println(".env file is empty")
os.Exit(1)
}
return env
}
func checkEnv(env map[string]string) {
// Is there an API key for openweathermap?
if val, ok := env["OPENWEATHERMAP_API_KEY"]; ok {
if val == "" {
print("OPENWEATHERMAP_API_KEY is not set")
os.Exit(1)
}
} else {
fmt.Println("OPENWEATHERMAP_API_KEY is not set")
os.Exit(1)
}
2024-10-26 14:31:51 +00:00
}