Files
slideshowApp/env/enviroment.go
Adrian Zürcher aa900d5e3b
All checks were successful
Build Slideshow App / build (amd64, .exe, windows) (push) Successful in 2m11s
Build Slideshow App / build (amd64, , linux) (push) Successful in 2m25s
Build Slideshow App / build (arm, 7, , linux) (push) Successful in 2m16s
Build Slideshow App / build (arm64, , linux) (push) Successful in 2m12s
fix enviroment bug
2026-02-03 09:19:06 +01:00

46 lines
832 B
Go

package env
import (
"os"
"strings"
"github.com/joho/godotenv"
)
const (
Env EnvKey = "ENV"
PhotoDir EnvKey = "PHOTO_DIR"
Host EnvKey = "HOST"
Port EnvKey = "PORT"
IntervalDefault EnvKey = "INTERVAL_DEFAULT"
LogPath EnvKey = "LOG_PATH"
)
type EnvKey string
func Load(path string) error {
if path == "" {
path = ".env"
}
return godotenv.Load(path)
}
func (key EnvKey) GetValue() string {
keyStr := string(key)
value := os.Getenv(keyStr)
if key == Port && value == "" {
value = "8080"
}
return value
}
func (key EnvKey) SetValue(value string) {
os.Setenv(string(key), value)
}
func (key EnvKey) GetBoolValue() bool {
value := strings.ToLower(os.Getenv(string(key)))
return value == "true" || value == "1"
}