valiwork

package module
v0.0.0-...-d26b8f4 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2022 License: MIT Imports: 5 Imported by: 0

README

ValiWork - validation framework

GoDoc Build Status Discord Keybase XLM

ValiWork is a validation framework that provides sane API and ability to write own validators that returns arbitrary things. It is goroutine-safe and fast.

Default validators

There are no necessity to enable default validators at all. But if you want to - call:

valiwork.InitializeDefaultValidators()

Default validators will return error.

There are no default validators ATM. Feel free to submit PR with them!

Validators registering and namespacing

Default validators using "T_N" scheme, where T is data type (string, int, int64, etc.) and N is a validator name (which can be a generic string). Please, use same naming scheme. Example good validators names:

  • string_check_for_very_rare_symbol_that_is_not_allowed
  • int64_check_if_in_bad_range
  • interface_check_if_able_to_be_TheVeryGoodStruct

Key idea is to help you debugging this thing (see debug section below).

Debug

Define VALIWORK_DEBUG environment variable and set it to true to get debug output. Default log module will be used for that.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrValidatorAlreadyRegistered appears when validator's name
	// passed to RegisterValidator function already used for other
	// validator function.
	ErrValidatorAlreadyRegistered = errors.New("validator with such name already registered")

	// ErrValidatorNotRegistered appears when trying to unregister
	// not registered validator function.
	ErrValidatorNotRegistered = errors.New("validator with such name wasn't registered")
)
View Source
var DEBUG bool

Functions

func RegisterValidator

func RegisterValidator(validatorName string, validator validators.ValidatorFunc) error

RegisterValidator registers validation function for later calling.

func UnregisterValidator

func UnregisterValidator(validatorName string) error

UnregisterValidator removes registered validator from list of known validators.

func Validate

func Validate(thing interface{}, validatorName string, optional ...interface{}) []interface{}

Validate launches validation function and returns it's result to caller. Optional might be used for passing additional options to validators.

func ValidateMany

func ValidateMany(thing interface{}, validatorNames []string, optional map[string][]interface{}) []interface{}

ValidateMany launches many validators using one-line-call. Optional might be used for passing parameters to validators, where key is a validator name and value (which is []interface{}) is a slice of parameters.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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