Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrInvalid = errorutil.UserError{
ID: "enum-invalid-value",
Message: "The value does not match the enumerator specification",
}
Functions ¶
func ValidateStruct ¶
Example (Float) ¶
package main import ( "github.com/adamluzsi/frameless/pkg/enum" ) func main() { type ExampleStruct struct { V float64 `enum:"2.5;4.2;"` } _ = enum.ValidateStruct(ExampleStruct{V: 4.2}) // no error _ = enum.ValidateStruct(ExampleStruct{V: 24.42}) // has error }
Output:
Example (Int) ¶
package main import ( "github.com/adamluzsi/frameless/pkg/enum" ) func main() { type ExampleStruct struct { V int `enum:"2,4,8,16,42,"` } _ = enum.ValidateStruct(ExampleStruct{V: 42}) // no error _ = enum.ValidateStruct(ExampleStruct{V: 24}) // has error }
Output:
Example (Slice) ¶
package main import ( "github.com/adamluzsi/frameless/pkg/enum" ) func main() { type ExampleStruct struct { V []string `enum:"FOO|BAR|BAZ|"` } _ = enum.ValidateStruct(ExampleStruct{V: []string{"FOO", "BAR", "BAZ"}}) // no error _ = enum.ValidateStruct(ExampleStruct{V: []string{"FOO", "BAB", "BAZ"}}) // has error because of BAB }
Output:
Example (String) ¶
package main import ( "github.com/adamluzsi/frameless/pkg/enum" ) func main() { type ExampleStruct struct { V string `enum:"A;B;C;"` } _ = enum.ValidateStruct(ExampleStruct{V: "A"}) // no error _ = enum.ValidateStruct(ExampleStruct{V: "D"}) // has error }
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.