74b46a5109
modified: main_dc/yalarba/api_yal/go.sum modified: main_dc/yalarba/api_yal/internal/config/config.go modified: main_dc/yalarba/api_yal/internal/router/router.go add stock middleware from chi
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
)
|
|
|
|
type Config struct {
|
|
DBHost string
|
|
DBPort string
|
|
DBUser string
|
|
DBPassword string
|
|
DBName string
|
|
JWTSecret string
|
|
ServerPort string
|
|
UploadPath string
|
|
LogLevel string
|
|
Environment string `yaml:"environment" env:"ENVIRONMENT" default:"development"`
|
|
AppPort string
|
|
CORS struct {
|
|
AllowedOrigins []string `yaml:"allowed_origins" env:"CORS_ALLOWED_ORIGINS"`
|
|
} `yaml:"cors"`
|
|
|
|
RateLimit struct {
|
|
Enabled bool `yaml:"enabled" env:"RATE_LIMIT_ENABLED" default:"false"`
|
|
RequestsPerSecond int `yaml:"requests_per_second" env:"RATE_LIMIT_REQUESTS" default:"100"`
|
|
} `yaml:"rate_limit"`
|
|
}
|
|
|
|
func Load() *Config {
|
|
return &Config{
|
|
DBHost: getEnv("DB_HOST", "localhost"),
|
|
DBPort: getEnv("DB_PORT", "5432"),
|
|
DBUser: getEnv("DB_USER", "postgres"),
|
|
DBPassword: getEnv("DB_PASSWORD", "postgres"),
|
|
DBName: getEnv("DB_NAME", "db_yal"),
|
|
JWTSecret: getEnv("JWT_SECRET", "secret"),
|
|
ServerPort: getEnv("SERVER_PORT", "8080"),
|
|
UploadPath: getEnv("UPLOAD_PATH", "./storage/uploads"),
|
|
LogLevel: getEnv("LOG_LEVEL", "debug"),
|
|
Environment: getEnv("ENVIRONMENT", "development"),
|
|
AppPort: getEnv("APP_PORT", "8088"),
|
|
}
|
|
}
|
|
|
|
func getEnv(key, defaultValue string) string {
|
|
if value := os.Getenv(key); value != "" {
|
|
return value
|
|
}
|
|
return defaultValue
|
|
}
|