validate

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(validators ...CustomValidator) plugins.Plugin

New returns an validator plugin. It accepts a list of CustomValidator functions.

By default, it will validate the struct with the Validate() method. If the struct does not have a Validate() method, it will be skipped.

If you want to add custom validation, you can pass a list of CustomValidator functions. The CustomValidator function should accept an interface{} and return an error.

Example:

type MyStruct struct {
	Str string
}

func (m MyStruct) Validate() error {
	if m.Str == "" {
		return fmt.Errorf("Str is empty")
	}
	return nil
}

Types

type CustomValidator

type CustomValidator func(any) error

Jump to

Keyboard shortcuts

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