add Block + Component, add TextComponent with min, max and regex validators and early NumberComponent
This commit is contained in:
47
main.go
Normal file
47
main.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"blocky/internal/block"
|
||||
"blocky/internal/block/text_component"
|
||||
text_component_validators "blocky/internal/block/text_component/validators"
|
||||
"blocky/internal/block/validation"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
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)
|
||||
|
||||
data := []byte(`{"title": "252", "age": 25 }`)
|
||||
// data := []byte(`{"title": "this is the title", "age": 25 }`)
|
||||
instance := &block.BlockInstance{}
|
||||
err := instance.FromJSON(b, data)
|
||||
if err != nil {
|
||||
fmt.Println("Error decoding object", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(instance)
|
||||
fmt.Println(instance.Components[0])
|
||||
fmt.Println(instance.Components[1])
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user