Documentation ¶
Index ¶
Constants ¶
const ( // ErrInvalidJSONBody represents an error message for an invalid JSON request body. ErrInvalidJSONBody = "Invalid JSON request body" // ErrUnicodeNotAllowedInField represents an error message for Unicode characters not allowed in a specific field. ErrUnicodeNotAllowedInField = "Unicode characters are not allowed in the '%s' field" // ErrInvalidXMLBody represents an error message for an invalid XML request body. ErrInvalidXMLBody = "Invalid XML request body" )
const ( // ErrFieldMustContainNumbersOnly represents an error message for a field that must contain only numbers. ErrFieldMustContainNumbersOnly = "The '%s' field must contain only numbers" // ErrFieldExceedsMaximumValue represents an error message for a field that exceeds the maximum allowed value. ErrFieldExceedsMaximumValue = "The '%s' field must not exceed %d" // ErrFieldExceedsMaximumDigits represents an error message for a field that exceeds the maximum allowed number of digits. ErrFieldExceedsMaximumDigits = "The '%s' field must not exceed %d digits" )
const ( // ErrFieldExceedsMaximumLength represents an error message for a field that exceeds the maximum allowed length. ErrFieldExceedsMaximumLength = "The '%s' field must not exceed %d characters" // ErrFieldsExceedMaximumLength represents an error message for fields that exceed the maximum allowed length. ErrFieldsExceedMaximumLength = "The '%s' fields must not exceed the maximum length" )
Variables ¶
var ConfigDefault = Config{ Rules: nil, Next: nil, ErrorHandler: DefaultErrorHandler, ContextKey: "", }
ConfigDefault is the default configuration for the Validator middleware.
Functions ¶
func DefaultErrorHandler ¶
DefaultErrorHandler is the default error handler function.
Types ¶
type Config ¶
type Config struct { // Rules is a slice of Restrictor implementations to be used for validation. Rules []Restrictor // Next defines a function to skip this middleware when returned true. // // Optional. Default: nil Next func(c *fiber.Ctx) bool // ErrorHandler is a function that handles the error response. // // Optional. Default: DefaultErrorHandler ErrorHandler func(c *fiber.Ctx, err error) error // ContextKey is the key used to store the validation result in the context. // // Note: This is most useful in advanced use cases for communicating internal context within the application, // especially for securing authentication and authorization. // // Optional. Default: nil ContextKey string }
Config defines the configuration for the Validator middleware.
type Error ¶
Error represents a validation error.
type RestrictNumberOnly ¶ added in v0.2.0
type RestrictNumberOnly struct { // Fields specifies the fields to check for number-only validation. Fields []string // Max specifies the maximum allowed value for the fields (optional). Max *int // MaxDigits specifies the maximum number of digits allowed in the field value (optional). MaxDigits *int }
RestrictNumberOnly is a Restrictor implementation that restricts fields to contain only numbers and allows setting an optional maximum value and maximum number of digits.
func (RestrictNumberOnly) Restrict ¶ added in v0.2.0
func (r RestrictNumberOnly) Restrict(c *fiber.Ctx) error
Restrict implements the Restrictor interface for RestrictNumberOnly. It checks the specified fields in the request body for numeric values and maximum limit based on the content type.
type RestrictStringLength ¶ added in v0.5.0
type RestrictStringLength struct { // Fields specifies the fields to check for string length validation. Fields []string // MaxLength specifies the maximum allowed length for the fields (optional). MaxLength *int }
RestrictStringLength is a Restrictor implementation that restricts the length of string fields and allows setting an optional maximum length.
func (RestrictStringLength) Restrict ¶ added in v0.5.0
func (r RestrictStringLength) Restrict(c *fiber.Ctx) error
Restrict implements the Restrictor interface for RestrictStringLength. It checks the specified fields in the request body for string length based on the content type.
type RestrictUnicode ¶
type RestrictUnicode struct { // Fields specifies the fields to check for Unicode characters. Fields []string }
RestrictUnicode is a Restrictor implementation that restricts the use of Unicode characters in specified fields of the request body.
func (RestrictUnicode) Restrict ¶
func (r RestrictUnicode) Restrict(c *fiber.Ctx) error
Restrict implements the Restrictor interface for RestrictUnicode. It checks the specified fields in the request body for Unicode characters based on the content type.
type Restrictor ¶
type Restrictor interface {
Restrict(c *fiber.Ctx) error
}
Restrictor is an interface for defining custom validation rules.