mirror of
https://github.com/R0m1k3/FlowReader.git
synced 2026-10-12 01:38:16 +02:00
42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
// Package config handles application configuration from environment variables.
|
|
package config
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
)
|
|
|
|
// Config holds all application configuration.
|
|
type Config struct {
|
|
Port string
|
|
DatabaseURL string
|
|
Environment string
|
|
}
|
|
|
|
// Load reads configuration from environment variables with sensible defaults.
|
|
func Load() *Config {
|
|
return &Config{
|
|
Port: getEnv("PORT", "8080"),
|
|
DatabaseURL: getEnv("DATABASE_URL", "postgres://flowreader:flowreader@db:5432/flowreader?sslmode=disable"),
|
|
Environment: getEnv("ENV", "development"),
|
|
}
|
|
}
|
|
|
|
// getEnv returns the value of an environment variable or a default value.
|
|
func getEnv(key, defaultValue string) string {
|
|
if value, exists := os.LookupEnv(key); exists {
|
|
return value
|
|
}
|
|
return defaultValue
|
|
}
|
|
|
|
// getEnvInt returns an integer environment variable or a default value.
|
|
func getEnvInt(key string, defaultValue int) int {
|
|
if value, exists := os.LookupEnv(key); exists {
|
|
if intValue, err := strconv.Atoi(value); err == nil {
|
|
return intValue
|
|
}
|
|
}
|
|
return defaultValue
|
|
}
|