Documentation
¶
Overview ¶
Package config provides configuration management for the GoForms application. It defines the configuration structures and validation logic used by the Viper-based configuration system.
Package config provides configuration module for Fx dependency injection ¶
Package config provides enhanced security configuration with modern best practices This replaces/enhances your existing internal/infrastructure/config/security.go
Package config provides validation utilities for Viper-based configuration ¶
Package config provides validation utilities for Viper-based configuration ¶
Package config provides validation utilities for Viper-based configuration ¶
Package config provides validation utilities for Viper-based configuration ¶
Package config provides validation utilities for Viper-based configuration ¶
Package config provides validation utilities for Viper-based configuration ¶
Package config provides validation utilities for Viper-based configuration ¶
Package config provides validation utilities for Viper-based configuration ¶
Package config provides validation utilities for Viper-based configuration ¶
Package config provides validation utilities for Viper-based configuration ¶
Package config provides validation utilities for Viper-based configuration ¶
Package config provides validation utilities for Viper-based configuration ¶
Package config provides validation utilities for Viper-based configuration ¶
Package config provides validation utilities for Viper-based configuration ¶
Package config provides validation utilities for Viper-based configuration ¶
Package config provides Viper-based configuration management for the GoForms application. It supports multiple configuration formats (JSON, YAML, TOML, ENV) and sources.
Index ¶
- Variables
- func NewViperConfigProvider() fx.Option
- type APIConfig
- type AdminUserConfig
- type AppConfig
- type AuthConfig
- type CORSConfig
- type CSPConfig
- type CSRFConfig
- type CacheConfig
- type Config
- type CookieSecurityConfig
- type DatabaseConfig
- type DatabaseLoggingConfig
- type DefaultUserConfig
- type EmailConfig
- type EncryptionConfig
- type EndpointLimit
- type FormConfig
- type LocalStorageConfig
- type LoggingConfig
- type MemoryConfig
- type RateLimitConfig
- type RedisConfig
- type S3StorageConfig
- type SecurityConfig
- func (s *SecurityConfig) GetCSPDirectives(appConfig *AppConfig) string
- func (s *SecurityConfig) GetCSRFSkipper() func(c echo.Context) bool
- func (s *SecurityConfig) GetRateLimitSkipper() func(c echo.Context) bool
- func (s *SecurityConfig) IsProduction() bool
- func (s *SecurityConfig) ShouldUseSecureCookies() bool
- func (s *SecurityConfig) Validate() error
- type SecurityHeadersConfig
- type SessionConfig
- type StorageConfig
- type TLSConfig
- type TrustProxyConfig
- type UserConfig
- type ValidationConfig
- type ValidationError
- type ValidationResult
- type ViperConfig
- type WebConfig
Constants ¶
This section is empty.
Variables ¶
var Module = fx.Module("config", NewViperConfigProvider(), fx.Provide(NewAppConfig), fx.Provide(NewDatabaseConfig), fx.Provide(NewSecurityConfig), fx.Provide(NewEmailConfig), fx.Provide(NewStorageConfig), fx.Provide(NewCacheConfig), fx.Provide(NewLoggingConfig), fx.Provide(NewSessionConfig), fx.Provide(NewAuthConfig), fx.Provide(NewFormConfig), fx.Provide(NewAPIConfig), fx.Provide(NewWebConfig), fx.Provide(NewUserConfig), )
Module provides the configuration module for Fx
Functions ¶
func NewViperConfigProvider ¶ added in v0.1.5
NewViperConfigProvider creates an Fx provider for Viper configuration
Types ¶
type APIConfig ¶ added in v0.1.5
type APIConfig struct {
Version string `json:"version"`
Prefix string `json:"prefix"`
Timeout time.Duration `json:"timeout"`
MaxRetries int `json:"max_retries"`
RateLimit RateLimitConfig `json:"rate_limit"`
}
APIConfig holds API-related configuration
func NewAPIConfig ¶ added in v0.1.5
NewAPIConfig provides API configuration
type AdminUserConfig ¶ added in v0.1.5
type AdminUserConfig struct {
Email string `json:"email"`
Password string `json:"password"`
Name string `json:"name"`
}
AdminUserConfig holds admin user configuration
type AppConfig ¶
type AppConfig struct {
// Application Info
Name string `json:"name"`
Version string `json:"version"`
Environment string `json:"environment"`
Debug bool `json:"debug"`
LogLevel string `json:"log_level"`
// Server Settings
URL string `json:"url"`
Scheme string `json:"scheme"`
Port int `json:"port"`
Host string `json:"host"`
ReadTimeout time.Duration `json:"read_timeout"`
WriteTimeout time.Duration `json:"write_timeout"`
IdleTimeout time.Duration `json:"idle_timeout"`
RequestTimeout time.Duration `json:"request_timeout"`
// Development Settings
ViteDevHost string `json:"vite_dev_host"`
ViteDevPort string `json:"vite_dev_port"`
}
AppConfig holds application-level configuration
func NewAppConfig ¶ added in v0.1.5
NewAppConfig provides app configuration
func (*AppConfig) GetServerPort ¶ added in v0.1.5
GetServerPort returns the server port
func (*AppConfig) GetServerURL ¶ added in v0.1.5
GetServerURL returns the server URL
func (*AppConfig) IsDevelopment ¶
IsDevelopment returns true if the application is running in development mode
type AuthConfig ¶ added in v0.1.5
type AuthConfig struct {
RequireEmailVerification bool `json:"require_email_verification"`
PasswordMinLength int `json:"password_min_length"`
PasswordRequireSpecial bool `json:"password_require_special"`
SessionTimeout time.Duration `json:"session_timeout"`
MaxLoginAttempts int `json:"max_login_attempts"`
LockoutDuration time.Duration `json:"lockout_duration"`
}
AuthConfig holds authentication-related configuration
func NewAuthConfig ¶ added in v0.1.5
func NewAuthConfig(cfg *Config) AuthConfig
NewAuthConfig provides authentication configuration
type CORSConfig ¶ added in v0.1.5
type CORSConfig struct {
Enabled bool `json:"enabled"`
AllowedOrigins []string `json:"allowed_origins"`
AllowedMethods []string `json:"allowed_methods"`
AllowedHeaders []string `json:"allowed_headers"`
ExposedHeaders []string `json:"exposed_headers"`
AllowCredentials bool `json:"allow_credentials"`
MaxAge int `json:"max_age"`
AllowOriginPatterns []string `json:"allow_origin_patterns"`
AllowWildcardOrigin bool `json:"allow_wildcard_origin"`
OptionStatusCode int `json:"option_status_code"`
}
CORSConfig represents enhanced CORS configuration
type CSPConfig ¶ added in v0.1.5
type CSPConfig struct {
Enabled bool `json:"enabled"`
DefaultSrc string `json:"default_src"`
ScriptSrc string `json:"script_src"`
StyleSrc string `json:"style_src"`
ImgSrc string `json:"img_src"`
ConnectSrc string `json:"connect_src"`
FontSrc string `json:"font_src"`
ObjectSrc string `json:"object_src"`
MediaSrc string `json:"media_src"`
FrameSrc string `json:"frame_src"`
FormAction string `json:"form_action"`
BaseURI string `json:"base_uri"`
ManifestSrc string `json:"manifest_src"`
WorkerSrc string `json:"worker_src"`
ReportURI string `json:"report_uri"`
ReportOnly bool `json:"report_only"`
}
CSPConfig represents enhanced Content Security Policy configuration
func (*CSPConfig) GetCSPHeaderName ¶ added in v0.1.5
GetCSPHeaderName returns the appropriate CSP header name
func (*CSPConfig) GetCSPHeaderValue ¶ added in v0.1.5
GetCSPHeaderValue returns the complete CSP header value
type CSRFConfig ¶
type CSRFConfig struct {
Enabled bool `json:"enabled"`
Secret string `json:"secret"`
TokenName string `json:"token_name"`
HeaderName string `json:"header_name"`
TokenLength int `json:"token_length"`
TokenLookup string `json:"token_lookup"`
ContextKey string `json:"context_key"`
CookieName string `json:"cookie_name"`
CookiePath string `json:"cookie_path"`
CookieDomain string `json:"cookie_domain"`
CookieHTTPOnly bool `json:"cookie_http_only"`
CookieSameSite string `json:"cookie_same_site"`
CookieMaxAge int `json:"cookie_max_age"`
CookieSecure bool `json:"cookie_secure"`
ErrorHandler string `json:"error_handler"`
SkipPaths []string `json:"skip_paths"`
}
CSRFConfig represents enhanced CSRF configuration
type CacheConfig ¶ added in v0.1.5
type CacheConfig struct {
Type string `json:"type"`
Redis RedisConfig `json:"redis"`
Memory MemoryConfig `json:"memory"`
TTL time.Duration `json:"ttl"`
}
CacheConfig holds cache-related configuration
func NewCacheConfig ¶ added in v0.1.5
func NewCacheConfig(cfg *Config) CacheConfig
NewCacheConfig provides cache configuration
type Config ¶
type Config struct {
App AppConfig `json:"app"`
Database DatabaseConfig `json:"database"`
Security SecurityConfig `json:"security"`
Email EmailConfig `json:"email"`
Storage StorageConfig `json:"storage"`
Cache CacheConfig `json:"cache"`
Logging LoggingConfig `json:"logging"`
Session SessionConfig `json:"session"`
Auth AuthConfig `json:"auth"`
Form FormConfig `json:"form"`
API APIConfig `json:"api"`
Web WebConfig `json:"web"`
User UserConfig `json:"user"`
}
Config represents the complete application configuration
func (*Config) GetConfigSummary ¶ added in v0.1.5
GetConfigSummary returns a summary of the current configuration
func (*Config) GetEnvironment ¶ added in v0.1.5
GetEnvironment returns the current environment
func (*Config) IsDevelopment ¶ added in v0.1.5
IsDevelopment returns true if running in development
func (*Config) IsProduction ¶ added in v0.1.5
IsProduction returns true if running in production
type CookieSecurityConfig ¶ added in v0.1.5
type CookieSecurityConfig struct {
Secure bool `json:"secure"`
HTTPOnly bool `json:"http_only"`
SameSite string `json:"same_site"`
Path string `json:"path"`
Domain string `json:"domain"`
MaxAge int `json:"max_age"`
}
CookieSecurityConfig represents default cookie security settings
type DatabaseConfig ¶
type DatabaseConfig struct {
// Common database settings
Driver string `json:"driver"`
Host string `json:"host"`
Port int `json:"port"`
Name string `json:"name"`
Username string `json:"username"`
Password string `json:"password"`
MaxOpenConns int `json:"max_open_conns"`
MaxIdleConns int `json:"max_idle_conns"`
ConnMaxLifetime time.Duration `json:"conn_max_lifetime"`
ConnMaxIdleTime time.Duration `json:"conn_max_idle_time"`
// PostgreSQL specific settings
SSLMode string `json:"ssl_mode"`
// MariaDB specific settings
RootPassword string `json:"root_password"`
// Logging configuration
Logging DatabaseLoggingConfig `json:"logging"`
}
DatabaseConfig holds all database-related configuration
func NewDatabaseConfig ¶ added in v0.1.5
func NewDatabaseConfig(cfg *Config) DatabaseConfig
NewDatabaseConfig provides database configuration
func (*DatabaseConfig) Validate ¶ added in v0.1.5
func (c *DatabaseConfig) Validate() error
Validate validates the database configuration
type DatabaseLoggingConfig ¶ added in v0.1.5
type DatabaseLoggingConfig struct {
// SlowThreshold is the threshold for logging slow queries
SlowThreshold time.Duration `json:"slow_threshold"`
// Parameterized enables logging of query parameters
Parameterized bool `json:"parameterized"`
// IgnoreNotFound determines whether to ignore record not found errors
IgnoreNotFound bool `json:"ignore_not_found"`
// LogLevel determines the verbosity of database logging
// Valid values: "silent", "error", "warn", "info"
LogLevel string `json:"log_level"`
}
DatabaseLoggingConfig holds database logging configuration
type DefaultUserConfig ¶ added in v0.1.5
type DefaultUserConfig struct {
Role string `json:"role"`
Permissions []string `json:"permissions"`
}
DefaultUserConfig holds default user configuration
type EmailConfig ¶ added in v0.1.5
type EmailConfig struct {
Host string `json:"host"`
Port int `json:"port"`
Username string `json:"username"`
Password string `json:"password"`
From string `json:"from"`
UseTLS bool `json:"use_tls"`
UseSSL bool `json:"use_ssl"`
Template string `json:"template"`
Timeout int `json:"timeout"`
MaxRetries int `json:"max_retries"`
}
EmailConfig holds email-related configuration
func NewEmailConfig ¶ added in v0.1.5
func NewEmailConfig(cfg *Config) EmailConfig
NewEmailConfig provides email configuration
type EncryptionConfig ¶ added in v0.1.5
type EncryptionConfig struct {
Key string `json:"key"`
Algorithm string `json:"algorithm"`
KeySize int `json:"key_size"`
SaltLength int `json:"salt_length"`
Iterations int `json:"iterations"`
EnableAES bool `json:"enable_aes"`
EnableChaCha20 bool `json:"enable_cha_cha20"`
}
EncryptionConfig represents encryption configuration
type EndpointLimit ¶ added in v0.1.5
type EndpointLimit struct {
RPS int `json:"rps"`
Burst int `json:"burst"`
Window time.Duration `json:"window"`
}
EndpointLimit represents specific rate limits for endpoints
type FormConfig ¶ added in v0.1.5
type FormConfig struct {
MaxFileSize int64 `json:"max_file_size"`
AllowedFileTypes []string `json:"allowed_file_types"`
MaxFields int `json:"max_fields"`
MaxMemory int64 `json:"max_memory"`
Validation ValidationConfig `json:"validation"`
}
FormConfig holds form-related configuration
func NewFormConfig ¶ added in v0.1.5
func NewFormConfig(cfg *Config) FormConfig
NewFormConfig provides form configuration
type LocalStorageConfig ¶ added in v0.1.5
type LocalStorageConfig struct {
Path string `json:"path"`
}
LocalStorageConfig holds local storage configuration
type LoggingConfig ¶ added in v0.1.5
type LoggingConfig struct {
Level string `json:"level"`
Format string `json:"format"`
Output string `json:"output"`
File string `json:"file"`
MaxSize int `json:"max_size"`
MaxBackups int `json:"max_backups"`
MaxAge int `json:"max_age"`
Compress bool `json:"compress"`
}
LoggingConfig holds logging-related configuration
func NewLoggingConfig ¶ added in v0.1.5
func NewLoggingConfig(cfg *Config) LoggingConfig
NewLoggingConfig provides logging configuration
type MemoryConfig ¶ added in v0.1.5
type MemoryConfig struct {
MaxSize int `json:"max_size"`
}
MemoryConfig holds memory cache configuration
type RateLimitConfig ¶
type RateLimitConfig struct {
Enabled bool `json:"enabled"`
RPS int `json:"rps"`
Requests int `json:"requests"` // Alias for RPS
Burst int `json:"burst"`
Window time.Duration `json:"window"`
PerIP bool `json:"per_ip"`
SkipPaths []string `json:"skip_paths"`
SkipMethods []string `json:"skip_methods"`
EndpointLimits map[string]EndpointLimit `json:"endpoint_limits"`
Store string `json:"store"` // memory, redis
KeyGenerator string `json:"key_generator"`
}
RateLimitConfig represents enhanced rate limiting configuration
type RedisConfig ¶ added in v0.1.5
type RedisConfig struct {
Host string `json:"host"`
Port int `json:"port"`
Password string `json:"password"`
DB int `json:"db"`
}
RedisConfig holds Redis cache configuration
type S3StorageConfig ¶ added in v0.1.5
type S3StorageConfig struct {
Bucket string `json:"bucket"`
Region string `json:"region"`
AccessKey string `json:"access_key"`
SecretKey string `json:"secret_key"`
Endpoint string `json:"endpoint"`
}
S3StorageConfig holds S3 storage configuration
type SecurityConfig ¶
type SecurityConfig struct {
CSRF CSRFConfig `json:"csrf"`
CORS CORSConfig `json:"cors"`
RateLimit RateLimitConfig `json:"rate_limit"`
CSP CSPConfig `json:"csp"`
TLS TLSConfig `json:"tls"`
Encryption EncryptionConfig `json:"encryption"`
SecurityHeaders SecurityHeadersConfig `json:"security_headers"`
CookieSecurity CookieSecurityConfig `json:"cookie_security"`
TrustProxy TrustProxyConfig `json:"trust_proxy"`
SecureCookie bool `json:"secure_cookie"`
Debug bool `json:"debug"`
}
SecurityConfig represents the enhanced security configuration
func NewSecurityConfig ¶ added in v0.1.5
func NewSecurityConfig(cfg *Config) SecurityConfig
NewSecurityConfig provides security configuration
func (*SecurityConfig) GetCSPDirectives ¶ added in v0.1.5
func (s *SecurityConfig) GetCSPDirectives(appConfig *AppConfig) string
GetCSPDirectives returns the Content Security Policy directives as a string
func (*SecurityConfig) GetCSRFSkipper ¶ added in v0.1.5
func (s *SecurityConfig) GetCSRFSkipper() func(c echo.Context) bool
GetCSRFSkipper returns a CSRF skipper function based on configuration
func (*SecurityConfig) GetRateLimitSkipper ¶ added in v0.1.5
func (s *SecurityConfig) GetRateLimitSkipper() func(c echo.Context) bool
GetRateLimitSkipper returns a rate limit skipper function based on configuration
func (*SecurityConfig) IsProduction ¶ added in v0.1.5
func (s *SecurityConfig) IsProduction() bool
IsProduction returns true if the application should use production security settings
func (*SecurityConfig) ShouldUseSecureCookies ¶ added in v0.1.5
func (s *SecurityConfig) ShouldUseSecureCookies() bool
ShouldUseSecureCookies returns true if cookies should be marked as secure
func (*SecurityConfig) Validate ¶ added in v0.1.5
func (s *SecurityConfig) Validate() error
Validate validates the security configuration
type SecurityHeadersConfig ¶ added in v0.1.5
type SecurityHeadersConfig struct {
Enabled bool `json:"enabled"`
XFrameOptions string `json:"x_frame_options"`
XContentTypeOptions string `json:"x_content_type_options"`
XXSSProtection string `json:"xxss_protection"`
ReferrerPolicy string `json:"referrer_policy"`
PermissionsPolicy string `json:"permissions_policy"`
StrictTransportSecurity string `json:"strict_transport_security"`
ContentTypeNoSniff bool `json:"content_type_no_sniff"`
}
SecurityHeadersConfig represents security headers configuration
type SessionConfig ¶ added in v0.1.5
type SessionConfig struct {
Type string `json:"type"`
Secret string `json:"secret"`
MaxAge time.Duration `json:"max_age"`
Domain string `json:"domain"`
Path string `json:"path"`
Secure bool `json:"secure"`
HTTPOnly bool `json:"http_only"`
SameSite string `json:"same_site"`
Store string `json:"store"`
StoreFile string `json:"store_file"`
CookieName string `json:"cookie_name"`
}
SessionConfig holds session-related configuration
func NewSessionConfig ¶ added in v0.1.5
func NewSessionConfig(cfg *Config) SessionConfig
NewSessionConfig provides session configuration
type StorageConfig ¶ added in v0.1.5
type StorageConfig struct {
Type string `json:"type"`
Local LocalStorageConfig `json:"local"`
S3 S3StorageConfig `json:"s3"`
MaxSize int64 `json:"max_size"`
AllowedExts []string `json:"allowed_exts"`
}
StorageConfig holds storage-related configuration
func NewStorageConfig ¶ added in v0.1.5
func NewStorageConfig(cfg *Config) StorageConfig
NewStorageConfig provides storage configuration
type TLSConfig ¶ added in v0.1.5
type TLSConfig struct {
Enabled bool `json:"enabled"`
CertFile string `json:"cert_file"`
KeyFile string `json:"key_file"`
MinVersion string `json:"min_version"`
CipherSuites []string `json:"cipher_suites"`
AutoCert bool `json:"auto_cert"`
AutoCertHost string `json:"auto_cert_host"`
}
TLSConfig represents enhanced TLS configuration
type TrustProxyConfig ¶ added in v0.1.5
type TrustProxyConfig struct {
Enabled bool `json:"enabled"`
TrustedProxies []string `json:"trusted_proxies"`
TrustedHeaders []string `json:"trusted_headers"`
}
TrustProxyConfig represents proxy trust configuration
type UserConfig ¶ added in v0.1.5
type UserConfig struct {
Admin AdminUserConfig `json:"admin"`
Default DefaultUserConfig `json:"default"`
}
UserConfig holds user-related configuration
func NewUserConfig ¶ added in v0.1.5
func NewUserConfig(cfg *Config) UserConfig
NewUserConfig provides user configuration
type ValidationConfig ¶ added in v0.1.5
type ValidationConfig struct {
StrictMode bool `json:"strict_mode"`
MaxErrors int `json:"max_errors"`
}
ValidationConfig holds form validation configuration
type ValidationError ¶ added in v0.1.5
ValidationError represents a configuration validation error
func (ValidationError) Error ¶ added in v0.1.5
func (e ValidationError) Error() string
type ValidationResult ¶ added in v0.1.5
type ValidationResult struct {
IsValid bool
Errors []ValidationError
}
ValidationResult contains the results of configuration validation
func ValidateConfig ¶ added in v0.1.5
func ValidateConfig(cfg *Config) ValidationResult
ValidateConfig validates the complete configuration with detailed error reporting
func ValidateEnvironmentVariables ¶ added in v0.1.5
func ValidateEnvironmentVariables() ValidationResult
ValidateEnvironmentVariables validates that required environment variables are set
func (*ValidationResult) AddError ¶ added in v0.1.5
func (r *ValidationResult) AddError(field, message string, value interface{})
AddError adds a validation error to the result
type ViperConfig ¶ added in v0.1.5
type ViperConfig struct {
// contains filtered or unexported fields
}
ViperConfig represents the Viper-based configuration loader
func NewViperConfig ¶ added in v0.1.5
func NewViperConfig() *ViperConfig
NewViperConfig creates a new Viper configuration instance
func (*ViperConfig) Load ¶ added in v0.1.5
func (vc *ViperConfig) Load() (*Config, error)
Load loads configuration using Viper with improved error handling
func (*ViperConfig) LoadForEnvironment ¶ added in v0.1.5
func (vc *ViperConfig) LoadForEnvironment(env string) (*Config, error)
LoadForEnvironment loads configuration for a specific environment
type WebConfig ¶ added in v0.1.5
type WebConfig struct {
TemplateDir string `json:"template_dir"`
StaticDir string `json:"static_dir"`
AssetsDir string `json:"assets_dir"`
ReadTimeout time.Duration `json:"read_timeout"`
WriteTimeout time.Duration `json:"write_timeout"`
IdleTimeout time.Duration `json:"idle_timeout"`
Gzip bool `json:"gzip"`
}
WebConfig holds web-related configuration
func NewWebConfig ¶ added in v0.1.5
NewWebConfig provides web configuration
Source Files
¶
- app.go
- config.go
- database.go
- module.go
- security.go
- services.go
- validation.go
- validation_api.go
- validation_app.go
- validation_auth.go
- validation_cache.go
- validation_database.go
- validation_email.go
- validation_form.go
- validation_helpers.go
- validation_logging.go
- validation_security.go
- validation_session.go
- validation_storage.go
- validation_user.go
- validation_web.go
- viper.go
- web.go