Documentation
¶
Overview ¶
Float Validators
Index ¶
- Constants
- func Must(value float64, err error) float64
- func Validate(value float64, rules ...ValidationRule) (float64, error)
- func ValidateFromString(src string, rules ...ValidationRule) (float64, error)
- type ValidationRule
- func Between(min, max float64) ValidationRule
- func DefaultValue(defaultValue float64) ValidationRule
- func Mandatory() ValidationRule
- func Matches(matches ...float64) ValidationRule
- func Max(max float64) ValidationRule
- func Min(min float64) ValidationRule
- func Optional(rules ...ValidationRule) ValidationRule
- func OverrideErrorMsg(validationError vError.ValidationError, rules ...ValidationRule) ValidationRule
- func Step(step float64) ValidationRule
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 ValidateFromString ¶
func ValidateFromString(src string, rules ...ValidationRule) (float64, error)
Convert to float64 and than validate.
Types ¶
type ValidationRule ¶
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 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.
Click to show internal directories.
Click to hide internal directories.