mirror of
https://github.com/eduardolat/pgbackweb.git
synced 2026-01-28 07:29:10 -06:00
38 lines
816 B
Go
38 lines
816 B
Go
package config
|
|
|
|
import (
|
|
"github.com/eduardolat/pgbackweb/internal/logger"
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
type Env struct {
|
|
PBW_ENCRYPTION_KEY *string
|
|
PBW_POSTGRES_CONN_STRING *string
|
|
}
|
|
|
|
// GetEnv returns the environment variables.
|
|
//
|
|
// If there is an error, it will log it and exit the program.
|
|
func GetEnv(disableLogs ...bool) *Env {
|
|
pickedDisableLogs := len(disableLogs) > 0 && disableLogs[0]
|
|
|
|
err := godotenv.Load()
|
|
if err == nil && !pickedDisableLogs {
|
|
logger.Info("using .env file")
|
|
}
|
|
|
|
env := &Env{
|
|
PBW_ENCRYPTION_KEY: getEnvAsString(getEnvAsStringParams{
|
|
name: "PBW_ENCRYPTION_KEY",
|
|
isRequired: true,
|
|
}),
|
|
PBW_POSTGRES_CONN_STRING: getEnvAsString(getEnvAsStringParams{
|
|
name: "PBW_POSTGRES_CONN_STRING",
|
|
isRequired: true,
|
|
}),
|
|
}
|
|
|
|
validateEnv(env)
|
|
return env
|
|
}
|