Documentation
¶
Index ¶
- func DurationValidator() []expr.Option
- func FQDNValidator() []expr.Option
- func FiskValidator(validation string) fisk.OptionValidator
- func FloatValidator() []expr.Option
- func HostnameValidator() []expr.Option
- func IPv4Validator() []expr.Option
- func IPv6Validator() []expr.Option
- func IPvValidator() []expr.Option
- func IntValidator() []expr.Option
- func RegexValidator() []expr.Option
- func ShellSafeValidator() []expr.Option
- func SurveyValidator(validation string, required bool) func(any) error
- func Validate(value any, validation string) (bool, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DurationValidator ¶
func FQDNValidator ¶ added in v0.0.2
func FiskValidator ¶
func FiskValidator(validation string) fisk.OptionValidator
FiskValidator is a fisk.OptionValidator that compatible with Validator() on arguments and flags
Example ¶
v := FiskValidator("is_int(value)")
err := v("42")
fmt.Printf("err: %v\n", err)
err = v("bob")
fmt.Printf("err: %v\n", err)
Output: err: <nil> err: validation using "is_int(value)" did not pass
func FloatValidator ¶
func HostnameValidator ¶ added in v0.0.2
func IPv4Validator ¶
func IPv6Validator ¶
func IPvValidator ¶
func IntValidator ¶
func RegexValidator ¶
func ShellSafeValidator ¶
func SurveyValidator ¶
SurveyValidator is a validator for github.com/AlecAivazis/survey
Example ¶
v := SurveyValidator("is_int(value)", true)
err := v("42")
fmt.Printf("err: %v\n", err)
err = v("bob")
fmt.Printf("err: %v\n", err)
Output: err: <nil> err: validation using "is_int(value)" did not pass
func Validate ¶
Validate validates value using the expr expression validation
Example (Compound) ¶
ok, err := Validate("hello", "is_shellsafe(value) && value == 'hello'")
fmt.Printf("valid: %v, err: %v\n", ok, err)
Output: valid: true, err: <nil>
Example (Duration) ¶
ok, _ := Validate("1h30m", "is_duration(value)")
fmt.Printf("valid: %v\n", ok)
ok, _ = Validate("bob", "is_duration(value)")
fmt.Printf("valid: %v\n", ok)
Output: valid: true valid: false
Example (IpAddress) ¶
ok, err := Validate("1.1.1.1", "is_ipv4(value)")
fmt.Printf("valid: %v, err: %v\n", ok, err)
ok, _ = Validate("bob", "is_ipv4(value)")
fmt.Printf("valid: %v\n", ok)
Output: valid: true, err: <nil> valid: false
Example (Numeric) ¶
ok, _ := Validate("42", "is_int(value)")
fmt.Printf("is_int: %v\n", ok)
ok, _ = Validate("3.14", "is_float(value)")
fmt.Printf("is_float: %v\n", ok)
Output: is_int: true is_float: true
Example (Regex) ¶
ok, err := Validate("hello123", `is_regex(value, "^[a-z]+[0-9]+$")`)
fmt.Printf("valid: %v, err: %v\n", ok, err)
ok, err = Validate("HELLO", `is_regex(value, "^[a-z]+$")`)
fmt.Printf("valid: %v, err: %v\n", ok, err)
Output: valid: true, err: <nil> valid: false, err: <nil>
Example (ShellSafe) ¶
ok, err := Validate("safe-input", "is_shellsafe(value)")
fmt.Printf("valid: %v, err: %v\n", ok, err)
ok, _ = Validate("bad;input", "is_shellsafe(value)")
fmt.Printf("valid: %v\n", ok)
Output: valid: true, err: <nil> valid: false
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.