vFloat

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: 5 Imported by: 0

Documentation

Overview

Float Validators

Index

Constants

View Source
const (
	Type = "float"

	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 float64, err error) float64

func Validate

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

func ValidateFromString

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

Convert to float64 and than validate.

Types

type ValidationRule

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

func Between

func Between(min, max float64) ValidationRule

Between Minimum and Maximum value

func DefaultValue

func DefaultValue(defaultValue float64) 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 added in v1.1.0

func Matches(matches ...float64) ValidationRule

Check for matches, return error if matches is not found

func Max

func Max(max float64) ValidationRule

Maximum value, returns error if more than max.

func Min

func Min(min float64) 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 float64) 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