Documentation
¶
Overview ¶
Package fiber adapts go-playground/validator/v10 into a fiber v3 StructValidator that fails as a lakta *errors.AppError{Code: VALIDATION}. Import it aliased (e.g. valfiber) to avoid clashing with gofiber/fiber.
ctx.Bind().Body(&dto) auto-invokes Validate; a struct-tag failure becomes an AppError the Phase 5 fiber ErrorHandler renders as application/problem+json with invalid_params. Field paths are normalized to json-tag dotted/bracketed form (user.email, items[0].qty) so they match the grpc transport byte-for-byte.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(opts ...Option) fiber.StructValidator
New builds a StructValidator. With no options it uses a default validator.New(); options can supply a pre-built *validator.Validate (custom validations) or change the rule tag. The json-tag field-name func is always registered so paths stay consistent with the grpc transport.
Types ¶
type Option ¶
type Option func(*StructValidator)
Option configures the StructValidator.
func WithTagName ¶
WithTagName overrides the rule-tag key (default "validate").
func WithValidate ¶
WithValidate supplies a caller-built *validator.Validate (registered custom validators, aliases, etc.).
type StructValidator ¶
type StructValidator struct {
// contains filtered or unexported fields
}
StructValidator satisfies fiber v3's fiber.StructValidator. A failure becomes an *errors.AppError{Code: VALIDATION} carrying one FieldViolation per failed field.
func (*StructValidator) Validate ¶
func (s *StructValidator) Validate(out any) error
Validate runs the validator over out. It returns nil on success; on validator.ValidationErrors it returns errors.Validation("validation failed") with one WithField per failed field. Any other error (e.g. an InvalidValidationError from a non-struct target) is wrapped as errors.Internal.