Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrMissingAppName = errors.New("application name is required") ErrInvalidPort = errors.New("port must be between 1 and 65535") ErrMissingDBDriver = errors.New("database driver is required") ErrMissingDBHost = errors.New("database host is required") ErrMissingDBUser = errors.New("database user is required") ErrMissingDBPassword = errors.New("database password is required") ErrMissingDBName = errors.New("database name is required") ErrMissingCSRFSecret = errors.New("CSRF secret is required when CSRF is enabled") ErrInvalidTimeout = errors.New("timeout duration must be positive") ErrInvalidRateLimit = errors.New("rate limit must be positive") ErrInvalidMaxConns = errors.New("max connections must be positive") ErrInvalidDBLogLevel = errors.New("invalid database log level") )
Validation errors
Functions ¶
This section is empty.
Types ¶
type APIConfig ¶ added in v0.1.5
type APIConfig struct { Version string `envconfig:"GOFORMS_API_VERSION" default:"v1"` Prefix string `envconfig:"GOFORMS_API_PREFIX" default:"/api"` RateLimit int `envconfig:"GOFORMS_API_RATE_LIMIT" default:"100"` Timeout int `envconfig:"GOFORMS_API_TIMEOUT" default:"30"` }
APIConfig holds API-related configuration
type AppConfig ¶
type AppConfig struct { // Application Info Name string `envconfig:"GOFORMS_APP_NAME" default:"GoFormX"` Version string `envconfig:"GOFORMS_APP_VERSION"` Env string `envconfig:"GOFORMS_APP_ENV" default:"production"` Debug bool `envconfig:"GOFORMS_APP_DEBUG" default:"false"` LogLevel string `envconfig:"GOFORMS_APP_LOGLEVEL" default:"info"` // Server Settings Scheme string `envconfig:"GOFORMS_APP_SCHEME" default:"http"` Port int `envconfig:"GOFORMS_APP_PORT" default:"8090"` Host string `envconfig:"GOFORMS_APP_HOST" default:"0.0.0.0"` ReadTimeout time.Duration `envconfig:"GOFORMS_READ_TIMEOUT" default:"5s"` WriteTimeout time.Duration `envconfig:"GOFORMS_WRITE_TIMEOUT" default:"10s"` IdleTimeout time.Duration `envconfig:"GOFORMS_IDLE_TIMEOUT" default:"120s"` RequestTimeout time.Duration `envconfig:"GOFORMS_REQUEST_TIMEOUT" default:"30s"` // Development Settings ViteDevHost string `envconfig:"GOFORMS_VITE_DEV_HOST" default:"localhost"` ViteDevPort string `envconfig:"GOFORMS_VITE_DEV_PORT" default:"3000"` }
AppConfig holds application-level configuration
func (*AppConfig) IsDevelopment ¶
IsDevelopment returns true if the application is running in development mode
type AuthConfig ¶ added in v0.1.5
type AuthConfig struct {
PasswordCost int `envconfig:"GOFORMS_PASSWORD_COST" default:"12"`
}
AuthConfig holds authentication-related configuration
type CacheConfig ¶ added in v0.1.5
type CacheConfig struct { Type string `envconfig:"GOFORMS_CACHE_TYPE" default:"memory"` TTL time.Duration `envconfig:"GOFORMS_CACHE_TTL" default:"1h"` MaxSize int `envconfig:"GOFORMS_CACHE_MAX_SIZE" default:"1000"` }
CacheConfig holds cache-related configuration
type Config ¶
type Config struct { App AppConfig Database DatabaseConfig Security SecurityConfig Email EmailConfig Storage StorageConfig Cache CacheConfig Logging LoggingConfig Session SessionConfig Auth AuthConfig Form FormConfig API APIConfig Web WebConfig User UserConfig }
Config represents the complete application configuration
type DatabaseConfig ¶
type DatabaseConfig struct { // MariaDB Configuration MariaDB struct { Host string `envconfig:"GOFORMS_MARIADB_HOST" validate:"required"` Port int `envconfig:"GOFORMS_MARIADB_PORT" default:"3306"` User string `envconfig:"GOFORMS_MARIADB_USER" validate:"required"` Password string `envconfig:"GOFORMS_MARIADB_PASSWORD" validate:"required"` Name string `envconfig:"GOFORMS_MARIADB_NAME" validate:"required"` MaxOpenConns int `envconfig:"GOFORMS_MARIADB_MAX_OPEN_CONNS" default:"25"` MaxIdleConns int `envconfig:"GOFORMS_MARIADB_MAX_IDLE_CONNS" default:"5"` ConnMaxLifetime time.Duration `envconfig:"GOFORMS_MARIADB_CONN_MAX_LIFETIME" default:"5m"` } `envconfig:"GOFORMS_MARIADB"` // PostgreSQL Configuration Postgres struct { Host string `envconfig:"GOFORMS_POSTGRES_HOST" validate:"required"` Port int `envconfig:"GOFORMS_POSTGRES_PORT" default:"5432"` User string `envconfig:"GOFORMS_POSTGRES_USER" validate:"required"` Password string `envconfig:"GOFORMS_POSTGRES_PASSWORD" validate:"required"` Name string `envconfig:"GOFORMS_POSTGRES_DB" validate:"required"` SSLMode string `envconfig:"GOFORMS_POSTGRES_SSLMODE" default:"disable"` MaxOpenConns int `envconfig:"GOFORMS_POSTGRES_MAX_OPEN_CONNS" default:"25"` MaxIdleConns int `envconfig:"GOFORMS_POSTGRES_MAX_IDLE_CONNS" default:"5"` ConnMaxLifetime time.Duration `envconfig:"GOFORMS_POSTGRES_CONN_MAX_LIFETIME" default:"5m"` } `envconfig:"GOFORMS_POSTGRES"` // Active database driver Driver string `envconfig:"GOFORMS_DB_DRIVER" default:"mariadb"` // Logging configuration Logging struct { // SlowThreshold is the threshold for logging slow queries SlowThreshold time.Duration `envconfig:"GOFORMS_DB_SLOW_THRESHOLD" default:"1s"` // Parameterized enables logging of query parameters Parameterized bool `envconfig:"GOFORMS_DB_LOG_PARAMETERS" default:"false"` // IgnoreNotFound determines whether to ignore record not found errors IgnoreNotFound bool `envconfig:"GOFORMS_DB_IGNORE_NOT_FOUND" default:"false"` // LogLevel determines the verbosity of database logging // Valid values: "silent", "error", "warn", "info" LogLevel string `envconfig:"GOFORMS_DB_LOG_LEVEL" default:"warn"` } `envconfig:"GOFORMS_DB_LOGGING"` }
DatabaseConfig holds all database-related configuration
type EmailConfig ¶ added in v0.1.5
type EmailConfig struct { Host string `envconfig:"GOFORMS_EMAIL_HOST"` Port int `envconfig:"GOFORMS_EMAIL_PORT" default:"587"` Username string `envconfig:"GOFORMS_EMAIL_USERNAME"` Password string `envconfig:"GOFORMS_EMAIL_PASSWORD"` From string `envconfig:"GOFORMS_EMAIL_FROM"` }
EmailConfig holds email-related configuration
type FormConfig ¶ added in v0.1.5
type FormConfig struct { MaxFileSize int64 `envconfig:"GOFORMS_MAX_FILE_SIZE" default:"10485760"` // 10MB AllowedTypes []string `envconfig:"GOFORMS_ALLOWED_FILE_TYPES" default:"image/jpeg,image/png,application/pdf"` MaxSubmissions int `envconfig:"GOFORMS_MAX_SUBMISSIONS" default:"1000"` RetentionDays int `envconfig:"GOFORMS_RETENTION_DAYS" default:"90"` }
FormConfig holds form-related configuration
type LoggingConfig ¶ added in v0.1.5
type LoggingConfig struct { Level string `envconfig:"GOFORMS_LOG_LEVEL" default:"info"` Format string `envconfig:"GOFORMS_LOG_FORMAT" default:"json"` Output string `envconfig:"GOFORMS_LOG_OUTPUT" default:"stdout"` MaxSize int `envconfig:"GOFORMS_LOG_MAX_SIZE" default:"100"` MaxBackups int `envconfig:"GOFORMS_LOG_MAX_BACKUPS" default:"3"` MaxAge int `envconfig:"GOFORMS_LOG_MAX_AGE" default:"28"` Compress bool `envconfig:"GOFORMS_LOG_COMPRESS" default:"true"` }
LoggingConfig holds logging-related configuration
type SecurityConfig ¶
type SecurityConfig struct { Debug bool `envconfig:"GOFORMS_DEBUG" default:"false"` FormRateLimit float64 `envconfig:"GOFORMS_FORM_RATE_LIMIT" default:"100"` FormRateLimitWindow time.Duration `envconfig:"GOFORMS_FORM_RATE_LIMIT_WINDOW" default:"1m"` SecureCookie bool `envconfig:"GOFORMS_SECURE_COOKIE" default:"true"` // Rate Limiting RateLimitEnabled bool `envconfig:"GOFORMS_RATE_LIMIT_ENABLED" default:"true"` RateLimit int `envconfig:"GOFORMS_RATE_LIMIT" default:"100"` RateBurst int `envconfig:"GOFORMS_RATE_BURST" default:"20"` RateLimitTimeWindow time.Duration `envconfig:"GOFORMS_RATE_LIMIT_TIME_WINDOW" default:"1m"` RateLimitPerIP bool `envconfig:"GOFORMS_RATE_LIMIT_PER_IP" default:"true"` // CORS settings CorsAllowedOrigins []string `envconfig:"GOFORMS_CORS_ALLOWED_ORIGINS" default:"http://localhost:3000"` CorsAllowedMethods []string `envconfig:"GOFORMS_CORS_ALLOWED_METHODS" default:"GET,POST,PUT,DELETE,OPTIONS"` CorsAllowedHeaders []string `envconfig:"GOFORMS_CORS_ALLOWED_HEADERS" default:"Content-Type,Authorization"` CorsAllowCredentials bool `envconfig:"GOFORMS_CORS_ALLOW_CREDENTIALS" default:"true"` CorsMaxAge int `envconfig:"GOFORMS_CORS_MAX_AGE" default:"3600"` // Form-specific CORS settings FormCorsAllowedOrigins []string `envconfig:"GOFORMS_FORM_CORS_ALLOWED_ORIGINS" default:"*"` FormCorsAllowedMethods []string `envconfig:"GOFORMS_FORM_CORS_ALLOWED_METHODS" default:"GET,POST,OPTIONS"` FormCorsAllowedHeaders []string `envconfig:"GOFORMS_FORM_CORS_ALLOWED_HEADERS" default:"Content-Type"` // CSRF settings CSRFConfig struct { Enabled bool `envconfig:"GOFORMS_CSRF_ENABLED" default:"true"` Secret string `envconfig:"GOFORMS_CSRF_SECRET" validate:"required"` } `envconfig:"GOFORMS_CSRF"` }
SecurityConfig contains security-related settings
type SessionConfig ¶ added in v0.1.5
type SessionConfig struct { Type string `envconfig:"GOFORMS_SESSION_TYPE" default:"none"` Secret string `envconfig:"GOFORMS_SESSION_SECRET"` TTL time.Duration `envconfig:"GOFORMS_SESSION_TTL" default:"24h"` Secure bool `envconfig:"GOFORMS_SESSION_SECURE" default:"true"` HTTPOnly bool `envconfig:"GOFORMS_SESSION_HTTP_ONLY" default:"true"` CookieName string `envconfig:"GOFORMS_SESSION_COOKIE_NAME" default:"session"` StoreFile string `envconfig:"GOFORMS_SESSION_STORE_FILE" default:"tmp/sessions.json"` }
SessionConfig holds session-related configuration
type StorageConfig ¶ added in v0.1.5
type StorageConfig struct { Type string `envconfig:"GOFORMS_STORAGE_TYPE" default:"local"` LocalDir string `envconfig:"GOFORMS_STORAGE_LOCAL_DIR" default:"./storage"` }
StorageConfig holds storage-related configuration
type UserConfig ¶ added in v0.1.5
type UserConfig struct { Admin struct { Email string `envconfig:"GOFORMS_ADMIN_EMAIL" validate:"required,email"` Password string `envconfig:"GOFORMS_ADMIN_PASSWORD" validate:"required"` FirstName string `envconfig:"GOFORMS_ADMIN_FIRST_NAME" validate:"required"` LastName string `envconfig:"GOFORMS_ADMIN_LAST_NAME" validate:"required"` } `envconfig:"GOFORMS_ADMIN"` Default struct { Email string `envconfig:"GOFORMS_USER_EMAIL" validate:"required,email"` Password string `envconfig:"GOFORMS_USER_PASSWORD" validate:"required"` FirstName string `envconfig:"GOFORMS_USER_FIRST_NAME" validate:"required"` LastName string `envconfig:"GOFORMS_USER_LAST_NAME" validate:"required"` } `envconfig:"GOFORMS_USER"` }
UserConfig holds user-related configuration
type WebConfig ¶ added in v0.1.5
type WebConfig struct { BaseURL string `envconfig:"GOFORMS_WEB_BASE_URL" default:"http://localhost:8090"` AssetsDir string `envconfig:"GOFORMS_WEB_ASSETS_DIR" default:"./assets"` TemplatesDir string `envconfig:"GOFORMS_WEB_TEMPLATES_DIR" default:"./templates"` }
WebConfig holds web-related configuration