2024-10-26 14:31:51 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-11-02 12:24:36 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
2024-11-02 18:11:56 +00:00
|
|
|
"github.com/LeRoid-hub/humiditycalc/configs"
|
2024-10-26 14:31:51 +00:00
|
|
|
"github.com/LeRoid-hub/humiditycalc/server"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2024-11-02 18:11:56 +00:00
|
|
|
env := configs.Load()
|
2024-11-02 12:24:36 +00:00
|
|
|
if val, ok := env["MODE"]; ok {
|
|
|
|
if strings.ToLower(val) == "both" {
|
|
|
|
checkEnv(env)
|
2024-11-02 17:10:52 +00:00
|
|
|
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()
|
2024-11-02 17:10:52 +00:00
|
|
|
server.Run(env)
|
2024-11-02 12:24:36 +00:00
|
|
|
}
|
2024-11-02 17:10:52 +00:00
|
|
|
} else {
|
|
|
|
// calc.Run()
|
|
|
|
server.Run(env)
|
2024-11-02 12:24:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|