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]) }