validator

package
v2.2.15 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ValidateEqualsIf validator.Func = func(fl validator.FieldLevel) bool {
	field := fl.Field()
	kind := field.Kind()

	params := ParseOneOfParam2(fl.Param())
	if len(params) < 3 || (len(params)-1)%2 != 0 {
		panic(fmt.Sprintf("Bad param number for equals_if %s", fl.FieldName()))
	}

	for i := 1; i < len(params); i += 2 {
		if !RequireCheckFieldValue(fl, params[i], params[i+1], false) {
			return true
		}
	}

	return CheckField(field, kind, params[0])
}

Functions

func AsBool

func AsBool(param string) bool

AsBool returns the parameter as a bool or panics if it can't convert

func AsFloat

func AsFloat(param string) float64

AsFloat returns the parameter as a float64 or panics if it can't convert

func AsInt

func AsInt(param string) int64

AsInt returns the parameter as a int64 or panics if it can't convert

func AsUint

func AsUint(param string) uint64

AsUint returns the parameter as a uint64 or panics if it can't convert

func CheckField

func CheckField(field reflect.Value, kind reflect.Kind, value string) bool

func HasValue

func HasValue(fl validator.FieldLevel) bool

HasValue is the validation function for validating if the current field's value is not the default static value.

func ParseOneOfParam2

func ParseOneOfParam2(s string) []string

func RequireCheckFieldValue

func RequireCheckFieldValue(fl validator.FieldLevel, param string, value string, defaultNotFoundValue bool) bool

func ValidateRegex added in v2.2.4

func ValidateRegex(regexp *regexp.Regexp) func(fl validator.FieldLevel) bool

Types

This section is empty.

Jump to

Keyboard shortcuts

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