Documentation ¶
Index ¶
- Variables
- func CallingVerb() schema.RefKey
- func GetDiscriminatorByVariant(variant reflect.Type) optional.Option[reflect.Type]
- func GetVariantByName(discriminator reflect.Type, name string) optional.Option[reflect.Type]
- func GetVariantByType(discriminator reflect.Type, variantType reflect.Type) optional.Option[string]
- func IsKnownExternalType(t reflect.Type) bool
- func IsSumTypeDiscriminator(discriminator reflect.Type) bool
- func Module() string
- func ReflectTypeToSchemaType(t reflect.Type) schema.Type
- func Register(options ...Registree)
- func ResetTypeRegistry()
- func TypeFromValue[T any, TP interface{ ... }](v TP) schema.Type
- type Ref
- type ReflectedDatabaseHandle
- type Registree
- type TypeRegistry
- type VerbExec
- type VerbResource
Constants ¶
This section is empty.
Variables ¶
var AllowAnyPackageForTesting = false
Functions ¶
func CallingVerb ¶
func GetDiscriminatorByVariant ¶
GetDiscriminatorByVariant returns the discriminator type for the given variant type.
func GetVariantByName ¶
GetVariantByName returns the variant type for the given discriminator and variant name.
func GetVariantByType ¶
GetVariantByType returns the variant name for the given discriminator and variant type.
func IsKnownExternalType ¶
func IsSumTypeDiscriminator ¶
IsSumTypeDiscriminator returns true if the given type is a sum type discriminator.
func ReflectTypeToSchemaType ¶
ReflectTypeToSchemaType returns the FTL schema for a Go reflect.Type.
func Register ¶
func Register(options ...Registree)
Register applies all the provided options to the singleton TypeRegistry
func ResetTypeRegistry ¶
func ResetTypeRegistry()
ResetTypeRegistry clears the contents of the singleton type registry for tests to guarantee determinism.
func TypeFromValue ¶
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 ¶
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 ReflectedDatabaseHandle ¶
type ReflectedDatabaseHandle struct { DBType string DB *once.Handle[*sql.DB] // configs Name string }
func GetDatabase ¶
func GetDatabase[T any]() *ReflectedDatabaseHandle
type Registree ¶
type Registree func(t *TypeRegistry)
Registree is a function that registers types with a TypeRegistry.
func Database ¶
func Database[T any](dbname string, init func(ref Ref) *ReflectedDatabaseHandle) Registree
func ExternalType ¶
ExternalType adds a non-FTL type to the type registry.
func ProvideResourcesForVerb ¶
func ProvideResourcesForVerb(verb any, rs ...VerbResource) Registree
ProvideResourcesForVerb registers any resources that must be provided when calling the given verb.
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.
type VerbResource ¶
VerbResource is a function that registers a resource for a Verb.