[BACKEND] Initialize Go backend structure and dependencies (#23)
This commit is contained in:
36
server/config/config.go
Normal file
36
server/config/config.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
// Config holds all application configuration.
|
||||
type Config struct {
|
||||
Port string
|
||||
DatabaseURL string
|
||||
JWTSecret string
|
||||
Environment string
|
||||
}
|
||||
|
||||
// Load reads configuration from environment variables.
|
||||
// A .env file is loaded if present but not required.
|
||||
func Load() *Config {
|
||||
// Best-effort .env load (not required in production)
|
||||
_ = godotenv.Load()
|
||||
|
||||
return &Config{
|
||||
Port: getEnv("PORT", "8080"),
|
||||
DatabaseURL: getEnv("DATABASE_URL", ""),
|
||||
JWTSecret: getEnv("JWT_SECRET", "dev-secret-change-me"),
|
||||
Environment: getEnv("ENVIRONMENT", "development"),
|
||||
}
|
||||
}
|
||||
|
||||
func getEnv(key, fallback string) string {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
return v
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
Reference in New Issue
Block a user