Documentation
¶
Overview ¶
block_validator.go
Index ¶
- func ConvertBlocksToMap(blocks []BlockInterface) []map[string]any
- func MarshalBlocksToJson(blocks []BlockInterface) (string, error)
- type Block
- func (b *Block) AddChild(child BlockInterface)
- func (b *Block) AddChildren(children []BlockInterface)
- func (b *Block) Children() []BlockInterface
- func (b *Block) HasParameter(key string) bool
- func (b *Block) ID() string
- func (b *Block) Parameter(key string) string
- func (b *Block) Parameters() map[string]string
- func (b *Block) SetChildren(children []BlockInterface)
- func (b *Block) SetID(id string)
- func (b *Block) SetParameter(key, value string)
- func (b *Block) SetParameters(parameters map[string]string)
- func (b *Block) SetType(blockType string)
- func (b *Block) ToJson() (string, error)
- func (b *Block) ToJsonObject() blockJsonObject
- func (b *Block) ToJsonPretty() (string, error)
- func (b *Block) ToMap() map[string]interface{}
- func (b *Block) Type() string
- type BlockBuilderInterface
- type BlockInterface
- func ConvertMapToBlock(blockMap map[string]any) (BlockInterface, error)
- func ConvertMapToBlocks(blocks []map[string]any) []BlockInterface
- func NewBlock() BlockInterface
- func NewBlockFromJson(blockJson string) (BlockInterface, error)
- func NewBlockFromMap(m map[string]any) BlockInterface
- func UnmarshalJsonToBlocks(blocksJson string) ([]BlockInterface, error)
- type BlockValidator
- type ChildrenInterface
- type IDInterface
- type ParametersInterface
- type ToHTMLInterface
- type ToJsonInterface
- type ToJsonObjectInterface
- type ToJsonPrettyInterface
- type ToMapInterface
- type TypeInterface
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertBlocksToMap ¶
func ConvertBlocksToMap(blocks []BlockInterface) []map[string]any
func MarshalBlocksToJson ¶
func MarshalBlocksToJson(blocks []BlockInterface) (string, error)
Types ¶
type Block ¶
type Block struct {
// contains filtered or unexported fields
}
func (*Block) AddChild ¶
func (b *Block) AddChild(child BlockInterface)
func (*Block) AddChildren ¶
func (b *Block) AddChildren(children []BlockInterface)
func (*Block) Children ¶
func (b *Block) Children() []BlockInterface
func (*Block) HasParameter ¶
func (*Block) Parameters ¶
func (*Block) SetChildren ¶
func (b *Block) SetChildren(children []BlockInterface)
func (*Block) SetParameter ¶
func (*Block) SetParameters ¶
func (*Block) ToJsonObject ¶
func (b *Block) ToJsonObject() blockJsonObject
func (*Block) ToJsonPretty ¶
type BlockBuilderInterface ¶
type BlockBuilderInterface interface {
WithID(string) BlockBuilderInterface
WithType(string) BlockBuilderInterface
WithParameters(map[string]string) BlockBuilderInterface
WithChildren([]BlockInterface) BlockBuilderInterface
Build() BlockInterface
}
func NewBlockBuilder ¶
func NewBlockBuilder() BlockBuilderInterface
type BlockInterface ¶
type BlockInterface interface {
IDInterface
ChildrenInterface
ParametersInterface
TypeInterface
// Serialization
ToMapInterface
ToJsonInterface
ToJsonObjectInterface
ToJsonPrettyInterface
}
func ConvertMapToBlock ¶
func ConvertMapToBlock(blockMap map[string]any) (BlockInterface, error)
ConvertMapToBlock converts a map to a block
The map must represent a valid block (have parameters like id, and type), otherwise an error will be returned
Parameters: - blockMap - a map[string]any to convert to a block
Returns: - BlockInterface - a block - error - if the map[string]any is not a valid block
func ConvertMapToBlocks ¶
func ConvertMapToBlocks(blocks []map[string]any) []BlockInterface
func NewBlock ¶
func NewBlock() BlockInterface
NewBlock returns a new block instance, and sets the default ID
func NewBlockFromJson ¶
func NewBlockFromJson(blockJson string) (BlockInterface, error)
func NewBlockFromMap ¶
func NewBlockFromMap(m map[string]any) BlockInterface
BlockFromMap creates a block from a map
func UnmarshalJsonToBlocks ¶
func UnmarshalJsonToBlocks(blocksJson string) ([]BlockInterface, error)
type BlockValidator ¶
type BlockValidator struct {
// contains filtered or unexported fields
}
BlockValidator is a thread-safe registry of block validators
func NewBlockValidator ¶
func NewBlockValidator() *BlockValidator
NewBlockValidator creates a new BlockValidator
func (*BlockValidator) Add ¶
func (v *BlockValidator) Add(blockType string, validator Validator)
Add registers a validator for a block type
func (*BlockValidator) Validate ¶
func (v *BlockValidator) Validate(block BlockInterface) error
Validate validates a block using its registered validator
type ChildrenInterface ¶
type ChildrenInterface interface {
Children() []BlockInterface
SetChildren([]BlockInterface)
AddChild(BlockInterface)
AddChildren([]BlockInterface)
}
type IDInterface ¶
type ParametersInterface ¶
type ToHTMLInterface ¶
type ToHTMLInterface interface {
ToHTML() string
}
type ToJsonInterface ¶
type ToJsonObjectInterface ¶
type ToJsonObjectInterface interface {
ToJsonObject() blockJsonObject
}
type ToJsonPrettyInterface ¶
type ToMapInterface ¶
type ToMapInterface interface {
ToMap() map[string]interface{}
}
type TypeInterface ¶
Click to show internal directories.
Click to hide internal directories.