reflection

package
v0.302.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllowAnyPackageForTesting = false

Functions

func GetDiscriminatorByVariant added in v0.223.0

func GetDiscriminatorByVariant(variant reflect.Type) optional.Option[reflect.Type]

GetDiscriminatorByVariant returns the discriminator type for the given variant type.

func GetFSM added in v0.230.0

func GetFSM(name string) optional.Option[ReflectedFSM]

GetFSM returns the FSM with the given name, if any.

func GetVariantByName added in v0.223.0

func GetVariantByName(discriminator reflect.Type, name string) optional.Option[reflect.Type]

GetVariantByName returns the variant type for the given discriminator and variant name.

func GetVariantByType added in v0.223.0

func GetVariantByType(discriminator reflect.Type, variantType reflect.Type) optional.Option[string]

GetVariantByType returns the variant name for the given discriminator and variant type.

func IsKnownExternalType added in v0.282.0

func IsKnownExternalType(t reflect.Type) bool

func IsSumTypeDiscriminator added in v0.223.0

func IsSumTypeDiscriminator(discriminator reflect.Type) bool

IsSumTypeDiscriminator returns true if the given type is a sum type discriminator.

func Module

func Module() string

Module returns the FTL module currently being executed.

func ReflectTypeToSchemaType added in v0.226.0

func ReflectTypeToSchemaType(t reflect.Type) schema.Type

ReflectTypeToSchemaType returns the FTL schema for a Go reflect.Type.

func Register added in v0.223.0

func Register(options ...Registree)

Register applies all the provided options to the singleton TypeRegistry

func ResetTypeRegistry added in v0.223.0

func ResetTypeRegistry()

ResetTypeRegistry clears the contents of the singleton type registry for tests to guarantee determinism.

func TypeFromValue added in v0.226.0

func TypeFromValue[T any, TP interface{ *T }](v TP) schema.Type

TypeFromValue reflects a schema.Type from a Go value.

The passed value must be a pointer to a value of the desired type. This is to ensure that interface values aren't dereferenced automatically by the Go compiler.

Types

type Ref

type Ref struct {
	Module string `json:"module"`
	Name   string `json:"name"`
}

Ref is an untyped reference to a symbol.

func FuncRef

func FuncRef(call any) Ref

FuncRef returns the Ref for a Go function.

Panics if called with a function outside FTL.

func ParseRef

func ParseRef(ref string) (Ref, error)

func RefFromProto

func RefFromProto(p *schemapb.Ref) Ref

func TypeRef

func TypeRef[T any]() Ref

TypeRef returns the Ref for a Go type.

Panics if called with a type outside of FTL.

func TypeRefFromValue

func TypeRefFromValue(v any) Ref

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) String

func (v Ref) String() string

func (Ref) ToProto

func (v Ref) ToProto() *schemapb.Ref

func (Ref) ToSchema added in v0.230.0

func (v Ref) ToSchema() *schema.Ref

func (*Ref) UnmarshalText

func (v *Ref) UnmarshalText(text []byte) error

type ReflectedFSM added in v0.230.0

type ReflectedFSM struct {
	Transitions []Transition
	Schema      *schema.FSM
}

type Registree added in v0.230.0

type Registree func(t *TypeRegistry)

Registree is a function that registers types with a TypeRegistry.

func ExternalType added in v0.282.0

func ExternalType(goType any) Registree

ExternalType adds a non-FTL type to the type registry.

func FSM added in v0.230.0

func FSM(name string, transitions ...Transition) Registree

FSM adds a finite state machine to the type registry.

func SumType added in v0.230.0

func SumType[Discriminator any](variants ...Discriminator) Registree

SumType adds a sum type and its variants to the type registry.

type Transition added in v0.230.0

type Transition struct {
	From reflect.Value
	To   reflect.Value
}

Transition represents a transition between two states in an FSM.

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.

Jump to

Keyboard shortcuts

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