Documentation
¶
Index ¶
Constants ¶
const ( // JSONDriver is the JSON struct field driver. // // Uses `json` field tag. JSONDriver = CodecDriver(iota) + 1 // YAMLDriver is the YAML struct field driver. // // Uses `yaml` field tag. YAMLDriver // XMLDriver is the XML struct field driver. // // Uses `xml` field tag. XMLDriver // TOMLDriver is the TOML struct field driver. // // Uses `toml` field tag. TOMLDriver // EnvironmentDriver is the environment struct field driver. // // Uses `env` field tag. EnvironmentDriver )
Variables ¶
var (
ErrInvalidCodecDriver = errors.New("validation: codec driver is invalid")
)
Functions ¶
This section is empty.
Types ¶
type CodecDriver ¶ added in v0.1.13
type CodecDriver uint8
CodecDriver is the codec algorithm to use for struct tag field scanning.
As validators scan struct fields, some of them might define tags for specific codecs (e.g. json). This causes a mismatch between the base and the encoded names and lead to confusion for routine callers.
A CodecDriver defines which tags of a codec mechanism to use for validator operations like error generation.
func ParseCodecDriver ¶ added in v0.1.13
func ParseCodecDriver(v string) (CodecDriver, error)
ParseCodecDriver allocates a new CodecDriver instance based on its string value.
func (CodecDriver) MarshalText ¶ added in v0.1.13
func (d CodecDriver) MarshalText() (text []byte, err error)
func (CodecDriver) String ¶ added in v0.1.13
func (d CodecDriver) String() string
func (*CodecDriver) UnmarshalText ¶ added in v0.1.13
func (d *CodecDriver) UnmarshalText(text []byte) error
type GoPlaygroundValidator ¶
type GoPlaygroundValidator struct {
// contains filtered or unexported fields
}
GoPlaygroundValidator a concrete implementation of Validator using go-playground/validator package.
func NewGoPlaygroundValidator ¶
func NewGoPlaygroundValidator(opts ...Option) GoPlaygroundValidator
NewGoPlaygroundValidator allocates a new GoPlaygroundValidator instance.
type Option ¶ added in v0.1.13
type Option func(*options)
Option is a function that modifies the validator behavior.
func WithCodecDriver ¶ added in v0.1.13
func WithCodecDriver(driver CodecDriver) Option
WithCodecDriver sets the codec driver to be used by the validator.
func WithRuleFunc ¶ added in v0.1.13
func WithRuleFunc(name string, fn ValidateFunc) Option
WithRuleFunc adds a custom validation rule routine to the validator.
type Rule ¶ added in v0.1.13
type Rule struct { // Name is the name of the validation rule. Name string // ValidateFunc is the function that performs the validation. ValidateFunc ValidateFunc }
Rule represents a validation rule with a name and a validation function.
func NewDateRule ¶ added in v0.1.13
func NewDateRule() Rule
NewDateRule is a custom validation function that checks if the provided value is a valid date string in the format "YYYY-MM-DD".
type ValidateFunc ¶ added in v0.1.13
ValidateFunc is a function type that defines a custom validation function.