add Int64Component
This commit is contained in:
25
main.go
25
main.go
@@ -2,6 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"blocky/internal/block"
|
||||
"blocky/internal/block/int64_component"
|
||||
int64_component_validators "blocky/internal/block/int64_component/validators"
|
||||
"blocky/internal/block/text_component"
|
||||
text_component_validators "blocky/internal/block/text_component/validators"
|
||||
"blocky/internal/block/validation"
|
||||
@@ -9,31 +11,32 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
b := &block.Block{}
|
||||
textComponent := text_component.NewTextComponent(
|
||||
"title",
|
||||
"Title",
|
||||
// validation.Required(),
|
||||
// validation.MaxLength(4),
|
||||
// nil,
|
||||
[]validation.ComponentOption{
|
||||
validation.Required(),
|
||||
validation.MaxLength(4),
|
||||
},
|
||||
[]text_component.TextComponentOption{
|
||||
text_component_validators.Regex("^\\d+$"),
|
||||
},
|
||||
)
|
||||
|
||||
b := &block.Block{}
|
||||
b.Components = append(b.Components, textComponent)
|
||||
|
||||
fmt.Println(textComponent.Name(), textComponent.Type())
|
||||
|
||||
numberComponent := block.NewNumberComponent("age", "Age")
|
||||
b.Components = append(b.Components, numberComponent)
|
||||
int64Component := int64_component.NewInt64Component(
|
||||
"year",
|
||||
"Year",
|
||||
[]validation.ComponentOption{},
|
||||
[]int64_component.Int64ComponentOption{
|
||||
int64_component_validators.Max(4),
|
||||
},
|
||||
)
|
||||
b.Components = append(b.Components, int64Component)
|
||||
|
||||
data := []byte(`{"title": "252", "age": 25 }`)
|
||||
// data := []byte(`{"title": "this is the title", "age": 25 }`)
|
||||
data := []byte(`{"title": "252", "year": 2 }`)
|
||||
// data := []byte(`{"year": 2}`)
|
||||
instance := &block.BlockInstance{}
|
||||
err := instance.FromJSON(b, data)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user