vInt

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Int Validators

Index

Constants

View Source
const (
	Type = "int"

	NotAnIntErrorFormat  = "{{.value}} is not an integer."
	MandatoryErrorFormat = "Must not be left empty."
	MinErrorFormat       = "Cannot be less than '{{.min}}'."
	MaxErrorFormat       = "Cannot be more than '{{.max}}'."
	BetweenErrorFormat   = "Must be between '{{.min}}' and '{{.max}}'."
	StepErrorFormat      = "Must be in step of '{{.step}}'."
	MatchesErrorFormat   = "Is not in the list, valid matches are '{{.matches|join \"and\"}}'."
)

Variables

This section is empty.

Functions

func Must

func Must(value int64, err error) int64

func MustMultiple

func MustMultiple(values []int64, err error) []int64

func Validate

func Validate(value int64, rules ...ValidationRule) (int64, error)

func ValidateFromString

func ValidateFromString(src string, rules ...ValidationRule) (int64, error)

Convert to int64 and than validate.

func ValidateFromStringMultiple

func ValidateFromStringMultiple(srcs []string, rules ...ValidationRule) ([]int64, error)

Convert to int64 and than validate. (Multiple)

func ValidateMultiple

func ValidateMultiple(values []int64, rules ...ValidationRule) ([]int64, error)

Types

type ValidationRule

type ValidationRule func(src *string, value *int64, hasError bool) error

func Between

func Between(min, max int64) ValidationRule

Between Minimum and Maximum value

func DefaultValue

func DefaultValue(defaultValue int64) ValidationRule

If the value is not set, set it to the default value.

Note: will only work while validating from string

func Mandatory

func Mandatory() ValidationRule

Make sure value is set, if not set the rule return a validation error

Note: will only work while validating from string

func Matches

func Matches(matches ...int64) ValidationRule

Check for matches, return error if matches is not found

func Max

func Max(max int64) ValidationRule

Maximum value, returns error if more than max.

func Min

func Min(min int64) ValidationRule

Minimum value, returns error if less than min.

func Optional

func Optional(rules ...ValidationRule) ValidationRule

Optional Value, if value is not set, return nil, otherwise go though the validation rules.

Note: will only work while validating from string

func OverrideErrorMsg

func OverrideErrorMsg(validationError vError.ValidationError, rules ...ValidationRule) ValidationRule

Override Error Message

func Step

func Step(step int64) ValidationRule

Number of step, if value not within number of steps returns an error.

Jump to

Keyboard shortcuts

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