MCPcopy
hub / github.com/PatchMon/PatchMon / Load

Function Load

server-source-code/internal/config/config.go:173–297  ·  view source on GitHub ↗

Load reads configuration from environment. Loads .env from current directory, or path from ENV_FILE if set.

()

Source from the content-addressed store, hash-verified

171// Load reads configuration from environment.
172// Loads .env from current directory, or path from ENV_FILE if set.
173func Load() (*Config, error) {
174 envPath := os.Getenv("ENV_FILE")
175 if envPath == "" {
176 envPath = ".env"
177 }
178 _ = godotenv.Load(envPath)
179
180 cfg := &Config{
181 DatabaseURL: getEnv("DATABASE_URL", ""),
182 DBConnMaxAttempts: getEnvInt("PM_DB_CONN_MAX_ATTEMPTS", 30),
183 DBConnWaitInterval: getEnvInt("PM_DB_CONN_WAIT_INTERVAL", 2),
184 DBConnectionLimit: getEnvInt("DB_CONNECTION_LIMIT", 30),
185 DBPoolTimeout: getEnvInt("DB_POOL_TIMEOUT", 20),
186 DBConnectTimeout: getEnvInt("DB_CONNECT_TIMEOUT", 10),
187 DBIdleTimeout: getEnvInt("DB_IDLE_TIMEOUT", 300),
188 DBMaxLifetime: getEnvInt("DB_MAX_LIFETIME", 1800),
189 DBTransactionMaxWait: getEnvInt("DB_TRANSACTION_MAX_WAIT", 10000),
190 DBTransactionTimeout: getEnvInt("DB_TRANSACTION_TIMEOUT", 30000),
191
192 Port: getEnvInt("PORT", 3000),
193 Env: getEnvEnv(),
194 Version: DefaultVersion,
195
196 JWTSecret: getEnv("JWT_SECRET", ""),
197 JWTExpiresIn: getEnv("JWT_EXPIRES_IN", "1h"),
198 AuthBrowserSessionCookies: getEnv("AUTH_BROWSER_SESSION_COOKIES", "") == "true",
199
200 CORSOrigin: getEnv("CORS_ORIGIN", "http://localhost:3000"),
201 AssetsDir: getEnv("ASSETS_DIR", ""),
202
203 EnableLogging: getEnv("ENABLE_LOGGING", "") == "true",
204 LogLevel: getEnv("LOG_LEVEL", "info"),
205
206 EnablePprof: getEnv("ENABLE_PPROF", "") == "true",
207 MemstatsIntervalSec: getEnvInt("MEMSTATS_INTERVAL_SEC", 60),
208
209 RedisHost: getEnv("REDIS_HOST", "localhost"),
210 RedisPort: getEnvInt("REDIS_PORT", 6379),
211 RedisPassword: getEnv("REDIS_PASSWORD", ""),
212 RedisUser: getEnv("REDIS_USER", ""),
213 RedisDB: getEnvInt("REDIS_DB", 0),
214 RedisTLS: getEnv("REDIS_TLS", "") == "true",
215 RedisConnectTimeout: getEnvInt("REDIS_CONNECT_TIMEOUT_MS", 60000),
216 RedisCommandTimeout: getEnvInt("REDIS_COMMAND_TIMEOUT_MS", 60000),
217
218 MaxTfaAttempts: getEnvInt("MAX_TFA_ATTEMPTS", 5),
219 TfaLockoutDurationMin: getEnvInt("TFA_LOCKOUT_DURATION_MINUTES", 30),
220 TfaRememberMeExpiresIn: getEnv("TFA_REMEMBER_ME_EXPIRES_IN", "30d"),
221
222 OidcEnabled: getEnv("OIDC_ENABLED", "") == "true",
223 OidcIssuerURL: getEnv("OIDC_ISSUER_URL", ""),
224 OidcClientID: getEnv("OIDC_CLIENT_ID", ""),
225 OidcClientSecret: getEnv("OIDC_CLIENT_SECRET", ""),
226 OidcRedirectURI: getEnv("OIDC_REDIRECT_URI", ""),
227 OidcScopes: getEnv("OIDC_SCOPES", "openid email profile groups"),
228 OidcAutoCreateUsers: getEnv("OIDC_AUTO_CREATE_USERS", "") == "true",
229 OidcDefaultRole: getEnv("OIDC_DEFAULT_ROLE", "user"),
230 OidcDisableLocalAuth: getEnv("OIDC_DISABLE_LOCAL_AUTH", "") == "true",

Callers 2

TestLoad_ValidEnvFunction · 0.85

Calls 5

ValidateMethod · 0.95
getEnvFunction · 0.85
getEnvEnvFunction · 0.85
getEnvBytesFunction · 0.85
getEnvIntFunction · 0.70

Tested by 2

TestLoad_ValidEnvFunction · 0.68