Documentation
¶
Overview ¶
Package validate provides configuration validation utilities for the xg2g application.
Package validate provides configuration validation utilities for the xg2g application.
Index ¶
- Variables
- type Error
- type LogLevel
- type ValidationError
- type Validator
- func (v *Validator) AddError(field, message string, value interface{})
- func (v *Validator) Custom(field string, value interface{}, validator func(interface{}) error)
- func (v *Validator) Directory(field, path string, mustExist bool)
- func (v *Validator) Err() error
- func (v *Validator) Errors() []Error
- func (v *Validator) IsValid() bool
- func (v *Validator) NonNegative(field string, value int)
- func (v *Validator) NotEmpty(field, value string)
- func (v *Validator) OneOf(field, value string, allowed []string)
- func (v *Validator) Path(field, path string)
- func (v *Validator) PathWithinRoot(field, path, rootDir string)
- func (v *Validator) Port(field string, port int)
- func (v *Validator) Positive(field string, value int)
- func (v *Validator) Range(field string, value, minVal, maxVal int)
- func (v *Validator) StreamURL(field, streamURL string)
- func (v *Validator) URL(field, value string, allowedSchemes []string)
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvalidLogLevel = &Error{
Field: "logLevel",
Message: "invalid log level (must be: debug, info, warn, error)",
}
)
Common validation errors
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error struct {
Field string // Field name that failed validation
Value interface{} // The invalid value
Message string // Human-readable error message
}
Error represents a validation error
type LogLevel ¶
type LogLevel string
LogLevel represents valid log levels
const ( // LogLevelDebug enables debug-level logging LogLevelDebug LogLevel = "debug" // LogLevelInfo enables info-level logging LogLevelInfo LogLevel = "info" // LogLevelWarn enables warn-level logging LogLevelWarn LogLevel = "warn" // LogLevelError enables error-level logging LogLevelError LogLevel = "error" )
Log level constants define the available logging severity levels.
func ParseLogLevel ¶
ParseLogLevel parses a string into a LogLevel
type ValidationError ¶
type ValidationError struct {
// contains filtered or unexported fields
}
ValidationError bundles multiple validation errors into a single error value.
func (ValidationError) Error ¶
func (e ValidationError) Error() string
Error implements the error interface for ValidationError.
func (ValidationError) Errors ¶
func (e ValidationError) Errors() []Error
Errors returns the individual validation errors making up the validation failure.
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator accumulates validation errors and can produce a ValidationError when invalid.
func (*Validator) Custom ¶
Custom allows custom validation logic The validator function should return an error if validation fails
func (*Validator) Directory ¶
Directory validates a directory path If mustExist is true, the directory must already exist If mustExist is false, the directory will be created if it doesn't exist
func (*Validator) NonNegative ¶
NonNegative validates that a number is non-negative (>= 0)
func (*Validator) Path ¶
Path validates a file path for security issues This function protects against path traversal attacks
func (*Validator) PathWithinRoot ¶
PathWithinRoot validates that a path stays within a specified root directory This provides stronger guarantees against directory escape attacks