Documentation ¶
Index ¶
- func And(validators ...func(value string) error) func(value string) error
- func IsAbsFilePath(value string) error
- func IsAny(value string) error
- func IsArchitecture(value string) error
- func IsBool(value string) error
- func IsCloudInitUserData(value string) error
- func IsCompressionAlgorithm(value string) error
- func IsCron(aliases []string) func(value string) error
- func IsDeviceID(value string) error
- func IsDeviceName(name string) error
- func IsHostname(name string) error
- func IsInRange(min int64, max int64) func(value string) error
- func IsInt64(value string) error
- func IsInterfaceName(value string) error
- func IsListOf(validator func(value string) error) func(value string) error
- func IsListenAddress(allowDNS bool, allowWildcard bool, requirePort bool) func(value string) error
- func IsNetwork(value string) error
- func IsNetworkAddress(value string) error
- func IsNetworkAddressCIDR(value string) error
- func IsNetworkAddressCIDRV4(value string) error
- func IsNetworkAddressCIDRV6(value string) error
- func IsNetworkAddressV4(value string) error
- func IsNetworkAddressV6(value string) error
- func IsNetworkMAC(value string) error
- func IsNetworkMTU(value string) error
- func IsNetworkName(value string) error
- func IsNetworkPort(value string) error
- func IsNetworkPortRange(value string) error
- func IsNetworkRange(value string) error
- func IsNetworkRangeV4(value string) error
- func IsNetworkRangeV6(value string) error
- func IsNetworkV4(value string) error
- func IsNetworkV6(value string) error
- func IsNetworkVLAN(value string) error
- func IsNotEmpty(value string) error
- func IsOneOf(valid ...string) func(value string) error
- func IsPCIAddress(value string) error
- func IsPriority(value string) error
- func IsRequestURL(value string) error
- func IsSize(value string) error
- func IsURLSegmentSafe(value string) error
- func IsUUID(value string) error
- func IsUint32(value string) error
- func IsUint32Range(value string) error
- func IsUint8(value string) error
- func IsValidCPUSet(value string) error
- func IsYAML(value string) error
- func Optional(validators ...func(value string) error) func(value string) error
- func Or(validators ...func(value string) error) func(value string) error
- func ParseNetworkVLANRange(vlan string) (int, int, error)
- func Required(validators ...func(value string) error) func(value string) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func And ¶ added in v0.7.0
And returns a function that runs one or more validators, all must pass without error.
func IsAbsFilePath ¶
IsAbsFilePath checks if value is an absolute file path.
func IsArchitecture ¶
IsArchitecture validates whether the value is a valid architecture name.
func IsCloudInitUserData ¶
IsCloudInitUserData checks value is valid cloud-init user data.
func IsCompressionAlgorithm ¶
IsCompressionAlgorithm validates whether a value is a valid compression algorithm and is available on the system.
func IsDeviceID ¶
IsDeviceID validates string is four lowercase hex characters suitable as Vendor or Device ID.
func IsDeviceName ¶
IsDeviceName checks name is 1-63 characters long, doesn't start with a full stop and contains only alphanumeric, forward slash, hyphen, colon, underscore and full stop characters.
func IsHostname ¶
IsHostname checks the string is valid DNS hostname.
func IsInterfaceName ¶
IsInterfaceName validates a real network interface name.
func IsListenAddress ¶
IsListenAddress returns a validator for a listen address.
func IsNetworkAddress ¶
IsNetworkAddress validates an IP (v4 or v6) address string.
func IsNetworkAddressCIDR ¶
IsNetworkAddressCIDR validates an IP address string in CIDR format.
func IsNetworkAddressCIDRV4 ¶
IsNetworkAddressCIDRV4 validates an IPv4 address string in CIDR format.
func IsNetworkAddressCIDRV6 ¶
IsNetworkAddressCIDRV6 validates an IPv6 address string in CIDR format.
func IsNetworkAddressV4 ¶
IsNetworkAddressV4 validates an IPv4 address string.
func IsNetworkAddressV6 ¶
IsNetworkAddressV6 validates an IPv6 address string.
func IsNetworkMAC ¶
IsNetworkMAC validates an Ethernet MAC address. e.g. "00:00:5e:00:53:01".
Example ¶
package main import ( "fmt" "github.com/lxc/incus/shared/validate" ) func main() { tests := []string{ "00:00:5e:00:53:01", "02:00:5e:10:00:00:00:01", // too long "00-00-5e-00-53-01", // invalid delimiter "0000.5e00.5301", // invalid delimiter "invalid", "", } for _, v := range tests { err := validate.IsNetworkMAC(v) fmt.Printf("%s, %t\n", v, err == nil) } }
Output: 00:00:5e:00:53:01, true 02:00:5e:10:00:00:00:01, false 00-00-5e-00-53-01, false 0000.5e00.5301, false invalid, false , false
func IsNetworkMTU ¶
IsNetworkMTU validates MTU number >= 1280 and <= 16384. Anything below 68 and the kernel doesn't allow IPv4, anything below 1280 and the kernel doesn't allow IPv6. So require an IPv6-compatible MTU as the low value and cap at the max ethernet jumbo frame size.
func IsNetworkName ¶
IsNetworkName validates a name usable for a network.
func IsNetworkPort ¶
IsNetworkPort validates an IP port number >= 0 and <= 65535.
func IsNetworkPortRange ¶
IsNetworkPortRange validates an IP port range in the format "port" or "start-end".
func IsNetworkRange ¶
IsNetworkRange validates an IP range in the format "start-end".
func IsNetworkRangeV4 ¶
IsNetworkRangeV4 validates an IPv4 range in the format "start-end".
func IsNetworkRangeV6 ¶
IsNetworkRangeV6 validates an IPv6 range in the format "start-end".
func IsPCIAddress ¶
IsPCIAddress validates whether a value is a PCI address.
Example ¶
package main import ( "fmt" "github.com/lxc/incus/shared/validate" ) func main() { tests := []string{ "0000:12:ab.0", // valid "0010:12:ab.0", // valid "0000:12:CD.0", // valid "12:ab.0", // valid "12:CD.0", // valid "0000:12:gh.0", // invalid hex "0000:12:GH.0", // invalid hex "12:gh.0", // invalid hex "12:GH.0", // invalid hex "000:12:CD.0", // wrong prefix "12.ab.0", // invalid format "", } for _, v := range tests { err := validate.IsPCIAddress(v) fmt.Printf("%s, %t\n", v, err == nil) } }
Output: 0000:12:ab.0, true 0010:12:ab.0, true 0000:12:CD.0, true 12:ab.0, true 12:CD.0, true 0000:12:gh.0, false 0000:12:GH.0, false 12:gh.0, false 12:GH.0, false 000:12:CD.0, false 12.ab.0, false , false
func IsRequestURL ¶
IsRequestURL checks value is a valid HTTP/HTTPS request URL.
func IsURLSegmentSafe ¶
IsURLSegmentSafe validates whether value can be used in a URL segment.
func IsUint32Range ¶
IsUint32Range validates whether the string is a uint32 range in the form "number" or "start-end".
func IsValidCPUSet ¶
IsValidCPUSet checks value is a valid CPU set.
Example ¶
package main import ( "fmt" "github.com/lxc/incus/shared/validate" ) func main() { tests := []string{ "1", // valid "1,2,3", // valid "1-3", // valid "1-3,4-6", // valid "1-3,4", // valid "abc", // invalid syntax "1-", // invalid syntax "1,", // invalid syntax "-1", // invalid syntax ",1", // invalid syntax "1,2,3,3", // invalid: Duplicate CPU "1-2,2", // invalid: Duplicate CPU "1-2,2-3", // invalid: Duplicate CPU } for _, t := range tests { err := validate.IsValidCPUSet(t) fmt.Printf("%v\n", err) } }
Output: <nil> <nil> <nil> <nil> <nil> Invalid CPU limit syntax Invalid CPU limit syntax Invalid CPU limit syntax Invalid CPU limit syntax Invalid CPU limit syntax Cannot define CPU multiple times Cannot define CPU multiple times Cannot define CPU multiple times
func Optional ¶
Optional wraps Required() function to make it return nil if value is empty string.
Example ¶
package main import ( "fmt" "github.com/lxc/incus/shared/validate" ) func main() { tests := []string{ "", "foo", "true", } for _, v := range tests { f := validate.Optional() fmt.Printf("%v ", f(v)) f = validate.Optional(validate.IsBool) fmt.Printf("%v\n", f(v)) } }
Output: <nil> <nil> <nil> Invalid value for a boolean "foo" <nil> <nil>
func Or ¶ added in v0.7.0
Or returns a function that runs one or more validators, at least one must pass without error.
func ParseNetworkVLANRange ¶
ParseNetworkVLANRange parses a VLAN range in the form "number" or "start-end". Returns the start number and the number of items in the range.
func Required ¶
Required returns a function that runs one or more validators, all must pass without error.
Example ¶
package main import ( "fmt" "github.com/lxc/incus/shared/validate" ) func main() { tests := []string{ "", "foo", "true", } for _, v := range tests { f := validate.Required() fmt.Printf("%v ", f(v)) f = validate.Required(validate.IsBool) fmt.Printf("%v\n", f(v)) } }
Output: <nil> Invalid value for a boolean "" <nil> Invalid value for a boolean "foo" <nil> <nil>
Types ¶
This section is empty.