validationjuice

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package validationjuice provides utility functions for validating struct fields based on their tags.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewNonNilValidator

func NewNonNilValidator(tagValue string) funccup.Validator

NewNonNilValidator creates a new validator that checks if a field is non-nil. The validator is associated with a tag value, and can be used to validate struct fields with that tag value.

func NewNonZeroValidator

func NewNonZeroValidator(tagValue string) funccup.Validator

NewNonZeroValidator creates a new validator that checks if a field is non-zero. The validator is associated with a tag value, and can be used to validate struct fields with that tag value.

Types

type ValidatorRegistry

type ValidatorRegistry struct {
	Validators map[string]funccup.Validator
}

ValidatorRegistry is a struct that holds a map of validators. Each validator is associated with a tag, and can be used to validate struct fields with that tag.

func (*ValidatorRegistry) AddValidator

func (r *ValidatorRegistry) AddValidator(tag string, validator funccup.Validator)

AddValidator adds a new validator to the ValidatorRegistry. The validator is associated with a tag, and can be used to validate struct fields with that tag.

func (*ValidatorRegistry) CheckTags

func (r *ValidatorRegistry) CheckTags(data interface{}, tagKey string) error

CheckTags checks the tags of the fields in a struct. If a field has a tag that matches a validator in the ValidatorRegistry, it will run that validator on the field. It returns an error if the data is not a struct or a pointer to a struct, or if a validator returns an error.

type ValidatorRegistryInterface

type ValidatorRegistryInterface interface {
	AddValidator(string, funccup.Validator)
	CheckTags(interface{}, string) error
}

ValidatorRegistryInterface is an interface that defines the methods that a ValidatorRegistry must implement.

func NewValidatorRegistry

func NewValidatorRegistry() ValidatorRegistryInterface

NewValidatorRegistry creates a new ValidatorRegistry and initializes its validators map. It returns a ValidatorRegistryInterface.

Jump to

Keyboard shortcuts

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