typeregistry

package
v0.202.1 Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithTypeRegistry

func ContextWithTypeRegistry(ctx context.Context, r *TypeRegistry) context.Context

ContextWithTypeRegistry adds a type registry to the given context.

Types

type TypeRegistry

type TypeRegistry struct {
	// GoTypes associates a type name with a Go type.
	GoTypes map[string]reflect.Type
	// SumTypes associates a sum type discriminator type name with its variant type names.
	SumTypes map[string][]string
}

TypeRegistry is a registry of types that can be instantiated by their qualified name. It also records sum types and their variants, for use in encoding and decoding.

FTL manages the type registry for you, so you don't need to create one yourself

func NewTypeRegistry

func NewTypeRegistry() *TypeRegistry

NewTypeRegistry creates a new type registry. The type registry is used to instantiate types by their qualified name at runtime.

func (*TypeRegistry) New

func (t *TypeRegistry) New(name string) (any, error)

New creates a new instance of the type from the qualified type name.

func (*TypeRegistry) RegisterSumType

func (t *TypeRegistry) RegisterSumType(discriminator reflect.Type, variants map[string]reflect.Type)

RegisterSumType registers a Go sum type with the type registry. Sum types are represented as enums in the FTL schema.

Jump to

Keyboard shortcuts

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