component

package
v1.0.2-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2023 License: LGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsComponentValid

func IsComponentValid(component Component, jsonSchemaBytes []byte) (bool, error)

func IsSchemaValid

func IsSchemaValid(jsonSchemaBytes1 []byte, jsonSchemaBytes2 []byte) (bool, error)

func SerializeComponentSchema

func SerializeComponentSchema(component Component) ([]byte, error)

Types

type Component

type Component interface {
	// Name returns the name of the component.
	Name() string
}

type ComponentMetadata

type ComponentMetadata interface {
	// SetID sets the ID of this component. It must only be set once
	SetID(TypeID) error
	// ID returns the ID of the component.
	ID() TypeID
	// New returns the marshaled bytes of the default value for the component struct.
	New() ([]byte, error)

	Encode(any) ([]byte, error)
	Decode([]byte) (any, error)
	Name() string
	GetSchema() []byte
}

ComponentMetadata is a high level representation of a user defined component struct.

func NewComponentMetadata

func NewComponentMetadata[T Component](opts ...ComponentOption[T]) (ComponentMetadata, error)

NewComponentMetadata creates a new component type. The function is used to create a new component of the type.

type ComponentOption

type ComponentOption[T any] func(c *componentMetadata[T]) //revive:disable-line:exported

ComponentOption is a type that can be passed to NewComponentMetadata to augment the creation of the component type.

func WithDefault

func WithDefault[T any](defaultVal T) ComponentOption[T]

WithDefault updated the created componentMetadata with a default value.

type TypeID

type TypeID int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL