36 lines
565 B
Go
36 lines
565 B
Go
package config
|
|
|
|
import (
|
|
"github.com/joho/godotenv"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
type Config struct {
|
|
DBHost string
|
|
DBPort string
|
|
DBName string
|
|
DBUser string
|
|
DBPassword string
|
|
}
|
|
|
|
func mustEnv(key string) string {
|
|
v := os.Getenv(key)
|
|
if v == "" {
|
|
log.Fatalf("missing required env var: %s", key)
|
|
}
|
|
return v
|
|
}
|
|
|
|
func Load() Config {
|
|
_ = godotenv.Load()
|
|
|
|
return Config{
|
|
DBHost: mustEnv("DB_HOST"),
|
|
DBPort: mustEnv("DB_PORT"),
|
|
DBName: mustEnv("DB_NAME"),
|
|
DBUser: mustEnv("DB_USERNAME"),
|
|
DBPassword: mustEnv("DB_PASSWORD"),
|
|
}
|
|
}
|