mirror of
https://github.com/LeRoid-hub/humiditycalc.git
synced 2025-01-30 19:24:56 +00:00
env
This commit is contained in:
parent
e72a267cd4
commit
80cdd9de4f
@ -1 +1,7 @@
|
||||
# humiditycalc
|
||||
# humiditycalc
|
||||
|
||||
## ENV
|
||||
MODES: CALC, WEATHER, BOTH
|
||||
BOTH is standard
|
||||
|
||||
OPENWEATHERMAP_API_KEY is required in WEATHER and BOTH mode
|
2
go.mod
2
go.mod
@ -1,3 +1,5 @@
|
||||
module github.com/LeRoid-hub/humiditycalc
|
||||
|
||||
go 1.22.2
|
||||
|
||||
require github.com/joho/godotenv v1.5.1 // indirect
|
||||
|
2
go.sum
Normal file
2
go.sum
Normal file
@ -0,0 +1,2 @@
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
1
internal/weather.go
Normal file
1
internal/weather.go
Normal file
@ -0,0 +1 @@
|
||||
package internal
|
47
main.go
47
main.go
@ -1,9 +1,54 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/LeRoid-hub/humiditycalc/server"
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
server.Run()
|
||||
env := loadEnv()
|
||||
if val, ok := env["MODE"]; ok {
|
||||
if strings.ToLower(val) == "both" {
|
||||
checkEnv(env)
|
||||
server.Run()
|
||||
} else if strings.ToLower(val) == "weather" {
|
||||
checkEnv(env)
|
||||
// weather.Run()
|
||||
} else if strings.ToLower(val) == "calc" {
|
||||
// calc.Run()
|
||||
server.Run()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
fmt.Println(val)
|
||||
if val == "" {
|
||||
print("OPENWEATHERMAP_API_KEY is not set")
|
||||
os.Exit(1)
|
||||
}
|
||||
} else {
|
||||
fmt.Println("OPENWEATHERMAP_API_KEY is not set")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ type result struct {
|
||||
AbsoluteHumidity float64
|
||||
}
|
||||
|
||||
// StartServer starts the HTTP server.
|
||||
// Run starts the HTTP server.
|
||||
func Run() {
|
||||
tmpl := template.Must(template.ParseFiles("./web/templates/index.html"))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user