major refactor of main.go

This commit is contained in:
2026-02-18 15:35:56 -08:00
parent be7e8a3c33
commit b49349eb26
8 changed files with 366 additions and 282 deletions
+36
View File
@@ -0,0 +1,36 @@
package config
import (
"log"
"os"
)
type Config struct {
APIKey string
DefaultCity string
DBHost string
DBPort string
DBUser string
DBPassword string
DBName string
}
func GetEnv(key string) string {
val := os.Getenv(key)
if val == "" {
log.Fatalf("missing required env var: %s", key)
}
return val
}
func Load() *Config {
return &Config{
APIKey: GetEnv("OPENWEATHERMAP_API_KEY"),
DefaultCity: GetEnv("WEATHER_CITY"),
DBHost: GetEnv("DB_HOST"),
DBPort: GetEnv("DB_PORT"),
DBUser: GetEnv("DB_USER"),
DBPassword: GetEnv("DB_PASSWORD"),
DBName: GetEnv("DB_NAME"),
}
}