add Int64Component
This commit is contained in:
21
internal/block/int64_component/validators/max.go
Normal file
21
internal/block/int64_component/validators/max.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package int64_component_validators
|
||||
|
||||
import (
|
||||
"blocky/internal/block/int64_component"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func Max(max int64) int64_component.Int64ComponentOption {
|
||||
return func(c *int64_component.Int64ComponentConfig) {
|
||||
c.Validators = append(c.Validators, func(value any) error {
|
||||
s, ok := value.(int64)
|
||||
if !ok {
|
||||
return fmt.Errorf("provided value bust be an int: %v", value)
|
||||
}
|
||||
if s > max {
|
||||
return fmt.Errorf("int must be %d or less", max)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user