Documentation ¶
Index ¶
- func ContextWithTypeRegistry(ctx context.Context, r *TypeRegistry) context.Context
- func Module() string
- func TypeRegistryFromContext(ctx context.Context) optional.Option[*TypeRegistry]
- type Ref
- type TypeRegistry
- func (t *TypeRegistry) GetDiscriminatorByVariant(variant reflect.Type) optional.Option[reflect.Type]
- func (t *TypeRegistry) GetVariantByName(discriminator reflect.Type, name string) optional.Option[reflect.Type]
- func (t *TypeRegistry) GetVariantByType(discriminator reflect.Type, variantType reflect.Type) optional.Option[string]
- func (t *TypeRegistry) IsSumTypeDiscriminator(discriminator reflect.Type) bool
- func (t *TypeRegistry) RegisterSumType(discriminator reflect.Type, variants map[string]reflect.Type)
- type TypeRegistryOption
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.
func TypeRegistryFromContext ¶
func TypeRegistryFromContext(ctx context.Context) optional.Option[*TypeRegistry]
TypeRegistryFromContext retrieves the TypeRegistry previously added to the context with ContextWithTypeRegistry.
Types ¶
type Ref ¶
Ref is an untyped reference to a symbol.
func FuncRef ¶
FuncRef returns the Ref for a Go function.
Panics if called with a function outside FTL.
func RefFromProto ¶
func TypeRefFromValue ¶
TypeRefFromValue returns the Ref for a Go value.
The value must be a named type such as a struct, enum, or sum type.
func (*Ref) UnmarshalText ¶
type TypeRegistry ¶
type TypeRegistry struct {
// contains filtered or unexported fields
}
TypeRegistry is used for dynamic type resolution at runtime. It stores associations between sum type discriminators 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(options ...TypeRegistryOption) *TypeRegistry
NewTypeRegistry creates a new TypeRegistry for instantiating types by their qualified name at runtime.
func (*TypeRegistry) GetDiscriminatorByVariant ¶
func (t *TypeRegistry) GetDiscriminatorByVariant(variant reflect.Type) optional.Option[reflect.Type]
GetDiscriminatorByVariant returns the discriminator type for the given variant type.
func (*TypeRegistry) GetVariantByName ¶
func (t *TypeRegistry) GetVariantByName(discriminator reflect.Type, name string) optional.Option[reflect.Type]
GetVariantByName returns the variant type for the given discriminator and variant name.
func (*TypeRegistry) GetVariantByType ¶
func (t *TypeRegistry) GetVariantByType(discriminator reflect.Type, variantType reflect.Type) optional.Option[string]
GetVariantByType returns the variant name for the given discriminator and variant type.
func (*TypeRegistry) IsSumTypeDiscriminator ¶
func (t *TypeRegistry) IsSumTypeDiscriminator(discriminator reflect.Type) bool
IsSumTypeDiscriminator returns true if the given type is a sum type discriminator.
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.
type TypeRegistryOption ¶
type TypeRegistryOption func(t *TypeRegistry)
TypeRegistryOption is a functional option for configuring a TypeRegistry.
func WithSumType ¶
func WithSumType[Discriminator any](variants ...Discriminator) TypeRegistryOption
WithSumType adds a sum type and its variants to the type registry.