ftl

package
v0.368.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Trace   = log.Trace
	Debug   = log.Debug
	Info    = log.Info
	Warn    = log.Warn
	Error   = log.Error
	Default = log.Default
)

Log levels.

Variables

View Source
var ErrLeaseHeld = fmt.Errorf("lease already held")

ErrLeaseHeld is returned when an attempt is made to acquire a lease that is already held.

Functions

func Call

func Call[Req, Resp any](ctx context.Context, verb Verb[Req, Resp], req Req) (Resp, error)

Call a Verb through the FTL Controller.

func CallEmpty added in v0.149.2

func CallEmpty(ctx context.Context, empty Empty) error

CallEmpty calls a Verb with no request or response through the FTL controller.

func CallSink added in v0.149.2

func CallSink[Req any](ctx context.Context, sink Sink[Req], req Req) error

CallSink calls a Sink through the FTL controller.

func CallSource added in v0.149.2

func CallSource[Resp any](ctx context.Context, source Source[Resp]) (Resp, error)

CallSource calls a Source through the FTL controller.

func FSMNext added in v0.337.0

func FSMNext(ctx context.Context, event any) error

FSMNext schedules the next event for an instance of the FSM from within a transition.

"instance" must uniquely identify an instance of the FSM. The event type must be valid for the state the FSM instance is currently transitioning to.

If the event is not valid for the state the FSM is in transition to, an error will be returned. If there is already a next event scheduled for the instance of the FSM an error will be returned.

Types

type ConfigType

type ConfigType interface{ any }

ConfigType is a type that can be used as a configuration value.

type ConfigValue

type ConfigValue[T ConfigType] struct {
	reflection.Ref
}

ConfigValue is a typed configuration key for the current module.

func Config

func Config[T ConfigType](name string) ConfigValue[T]

Config declares a typed configuration key for the current module.

func (ConfigValue[T]) Get

func (c ConfigValue[T]) Get(ctx context.Context) (out T)

Get returns the value of the configuration key from FTL.

func (ConfigValue[T]) GoString added in v0.138.2

func (c ConfigValue[T]) GoString() string

func (ConfigValue[T]) String

func (c ConfigValue[T]) String() string

type Database added in v0.183.0

type Database struct {
	Name   string
	DBType modulecontext.DBType
	// contains filtered or unexported fields
}

func PostgresDatabase

func PostgresDatabase(name string) Database

PostgresDatabase returns a handler for the named database.

func (Database) Get added in v0.183.0

func (d Database) Get(ctx context.Context) *sql.DB

Get returns the SQL DB connection for the database.

func (Database) String added in v0.183.0

func (d Database) String() string

type Empty added in v0.149.2

type Empty func(context.Context) error

An Empty is a function that does not accept input or return output.

type FSMHandle added in v0.202.0

type FSMHandle struct {
	// contains filtered or unexported fields
}

func FSM added in v0.202.0

func FSM(name string, transitions ...FSMTransition) *FSMHandle

FSM creates a new finite-state machine.

func (*FSMHandle) Send added in v0.226.0

func (f *FSMHandle) Send(ctx context.Context, instance string, event any) error

Send an event to an instance of the FSM.

"instance" must uniquely identify an instance of the FSM. The event type must be valid for the current state of the FSM instance.

If the FSM instance is not executing, a new one will be started. If the event is not valid for the current state, an error will be returned.

To schedule the next event for an instance of the FSM from within a transition, use ftl.FSMNext(ctx, event).

type FSMTransition added in v0.202.0

type FSMTransition struct {
	// contains filtered or unexported fields
}

func Start added in v0.202.0

func Start[In any](state Sink[In]) FSMTransition

Start specifies a start state in an FSM.

func Transition added in v0.202.0

func Transition[FromIn, ToIn any](from Sink[FromIn], to Sink[ToIn]) FSMTransition

Transition specifies a transition in an FSM.

The "event" triggering the transition is the input to the "from" state.

type Handle added in v0.181.0

type Handle[T any] interface {
	Get(ctx context.Context) T
}

Handle represents a resource that can be retrieved such as a database connection, secret, etc.

type LeaseHandle added in v0.199.0

type LeaseHandle struct {
	// contains filtered or unexported fields
}

func Lease added in v0.199.0

func Lease(ctx context.Context, ttl time.Duration, key ...string) (LeaseHandle, error)

Lease acquires a new exclusive lease on a resource uniquely identified by [key].

The [ttl] defines the time after which the lease will be released if no heartbeat has been received. It must be >= 5s.

Each [key] is scoped to the module that acquires the lease.

Returns ErrLeaseHeld if the lease is already held.

func (LeaseHandle) Err added in v0.199.0

func (l LeaseHandle) Err() error

Err returns an error if the lease heartbeat fails.

func (LeaseHandle) Release added in v0.199.0

func (l LeaseHandle) Release() error

Release attempts to release the lease.

Will return an error if the heartbeat failed. In this situation there are no guarantees that the lease was held to completion.

type Logger

type Logger = log.Logger

Logger is a levelled printf-style logger with support for structured attributes.

func LoggerFromContext

func LoggerFromContext(ctx context.Context) *Logger

LoggerFromContext retrieves the current logger from the Context.

type MapHandle added in v0.181.0

type MapHandle[T, U any] struct {
	// contains filtered or unexported fields
}

func Map added in v0.181.0

func Map[T, U any](getter Handle[T], fn func(context.Context, T) (U, error)) *MapHandle[T, U]

Map an FTL resource type to a new type.

func (*MapHandle[T, U]) Get added in v0.181.0

func (mh *MapHandle[T, U]) Get(ctx context.Context) U

Get the mapped value.

type Option

type Option[T any] struct {
	// contains filtered or unexported fields
}

An Option type is a type that can contain a value or nothing.

func Nil

func Nil[T any](ptr T) Option[T]

Nil returns an Option that is invalid if the value is nil, otherwise the value.

If the type is not nillable (slice, map, chan, ptr, interface) this will panic.

func None

func None[T any]() Option[T]

None returns an Option that contains nothing.

func Ptr

func Ptr[T any](ptr *T) Option[T]

Ptr returns an Option that is invalid if the pointer is nil, otherwise the dereferenced pointer.

func Some

func Some[T any](value T) Option[T]

Some returns an Option that contains a value.

func Zero

func Zero[T any](value T) Option[T]

Zero returns an Option that is invalid if the value is the zero value, otherwise the value.

func (Option[T]) Default

func (o Option[T]) Default(value T) T

Default returns the Option value if it is present, otherwise it returns the value passed.

func (Option[T]) Get

func (o Option[T]) Get() (T, bool)

Get returns the value and a boolean indicating if the Option contains a value.

func (Option[T]) GoString

func (o Option[T]) GoString() string

func (Option[T]) Marshal added in v0.203.0

func (o Option[T]) Marshal(
	w *bytes.Buffer,
	encode func(v reflect.Value, w *bytes.Buffer) error,
) error

func (Option[T]) MarshalJSON

func (o Option[T]) MarshalJSON() ([]byte, error)

func (Option[T]) MustGet

func (o Option[T]) MustGet() T

MustGet returns the value. It panics if the Option contains nothing.

func (Option[T]) Ok

func (o Option[T]) Ok() bool

Ok returns true if the Option contains a value.

func (Option[T]) Ptr

func (o Option[T]) Ptr() *T

Ptr returns a pointer to the value if the Option contains a value, otherwise nil.

func (*Option[T]) Scan

func (o *Option[T]) Scan(src any) error

func (Option[T]) String

func (o Option[T]) String() string

func (*Option[T]) Unmarshal added in v0.203.0

func (o *Option[T]) Unmarshal(
	d *json.Decoder,
	isNull bool,
	decode func(d *json.Decoder, v reflect.Value) error,
) error

func (*Option[T]) UnmarshalJSON

func (o *Option[T]) UnmarshalJSON(data []byte) error

func (Option[T]) Value

func (o Option[T]) Value() (driver.Value, error)

type SecretType

type SecretType interface{ any }

SecretType is a type that can be used as a secret value.

type SecretValue

type SecretValue[T SecretType] struct {
	reflection.Ref
}

SecretValue is a typed secret for the current module.

func Secret

func Secret[T SecretType](name string) SecretValue[T]

Secret declares a typed secret for the current module.

func (SecretValue[T]) Get

func (s SecretValue[T]) Get(ctx context.Context) (out T)

Get returns the value of the secret from FTL.

func (SecretValue[T]) GoString added in v0.138.2

func (s SecretValue[T]) GoString() string

func (SecretValue[T]) String

func (s SecretValue[T]) String() string

type Sink

type Sink[Req any] func(context.Context, Req) error

A Sink is a function that accepts input but returns nothing.

type Source

type Source[Resp any] func(context.Context) (Resp, error)

A Source is a function that does not accept input but returns output.

type SubscriptionHandle added in v0.240.0

type SubscriptionHandle[E any] struct {
	Topic *schema.Ref
	Name  string
}

func Subscription added in v0.232.0

func Subscription[E any](topic TopicHandle[E], name string) SubscriptionHandle[E]

Subscription declares a subscription to a topic

Sinks can consume events from the subscription by including a "ftl:subscibe <subscription_name>" directive

type TopicHandle added in v0.240.0

type TopicHandle[E any] struct {
	Ref *schema.Ref
}

func Topic added in v0.232.0

func Topic[E any](name string) TopicHandle[E]

Topic declares a topic

Topics publish events, and subscriptions can listen to them.

func (TopicHandle[E]) Publish added in v0.240.0

func (t TopicHandle[E]) Publish(ctx context.Context, event E) error

Publish publishes an event to a topic

type Unit

type Unit struct{}

Unit is a type that has no value.

It can be used as a parameter or return value to indicate that a function does not accept or return any value.

type Verb

type Verb[Req, Resp any] func(context.Context, Req) (Resp, error)

A Verb is a function that accepts input and returns output.

Directories

Path Synopsis
Package ftltest contains test utilities for the ftl package.
Package ftltest contains test utilities for the ftl package.

Jump to

Keyboard shortcuts

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