validator

package module
v1.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidStruct = func(err error) error {
	var out errors.CustomError

	if ve, ok := err.(validator.ValidationErrors); ok {
		for _, e := range ve {
			for _, ie := range strings.Split(e.Error(), "\n") {
				out, _ = errors.Wrap(out, ie).(errors.CustomError)
			}
		}
	}

	out, _ = errors.Wrap(out, "invalid struct").(errors.CustomError)

	return out.WithKind(errors.KindInvalidInput)
}

ErrInvalidStruct is the error returned when the struct is invalid.

Functions

This section is empty.

Types

type CustomValidator

type CustomValidator interface {
	// Tag returns the tag identifier used in struct field validation tags (e.g., `validate:"tag"`).
	Tag() string

	// Func returns the validator.Func that performs the validation logic.
	Func() validator.Func
}

CustomValidator defines the interface that custom validators must implement. It requires methods to return the validation tag, function, and translation details.

type Option

type Option func(*val)

Option is a function that configures a Validator.

func WithCustomValidator

func WithCustomValidator(cv CustomValidator) Option

WithCustomValidator adds custom validators to the validator.

type Validator

type Validator interface {
	// Validate validates a struct given validate annotations.
	Validate(ctx context.Context, s any) error
}

Validator validates structs given validate annotations. Based on https://github.com/go-playground/validator.

func New

func New(options ...Option) Validator

New creates a new validator.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL