Documentation ¶
Index ¶
- Constants
- func DatabasesFromSecrets(ctx context.Context, module string, secrets map[string][]byte) (map[string]Database, error)
- type Builder
- func (b *Builder) AddAllowedDirectVerb(ref reflection.Ref) *Builder
- func (b *Builder) AddConfigs(configs map[string][]byte) *Builder
- func (b *Builder) AddDatabases(databases map[string]Database) *Builder
- func (b *Builder) AddSecrets(secrets map[string][]byte) *Builder
- func (b *Builder) Build() ModuleContext
- func (b *Builder) UpdateForTesting(mockVerbs map[schema.RefKey]Verb, allowDirectVerbBehavior bool, ...) *Builder
- type DBType
- type Database
- type DirectBehavior
- type DynamicModuleContext
- type LeaseClient
- type MockBehavior
- type ModuleContext
- func (m ModuleContext) BehaviorForVerb(ref schema.Ref) (optional.Option[VerbBehavior], error)
- func (m ModuleContext) GetConfig(name string, value any) error
- func (m ModuleContext) GetDatabase(name string, dbType DBType) (string, error)
- func (m ModuleContext) GetSecret(name string, value any) error
- func (m ModuleContext) MockLeaseClient() optional.Option[LeaseClient]
- func (m ModuleContext) ToProto() *ftlv1.ModuleContextResponse
- type ModuleContextSupplier
- type Verb
- type VerbBehavior
Constants ¶
const (
DBTypePostgres = DBType(ftlv1.ModuleContextResponse_POSTGRES)
)
Variables ¶
This section is empty.
Functions ¶
func DatabasesFromSecrets ¶ added in v0.214.0
func DatabasesFromSecrets(ctx context.Context, module string, secrets map[string][]byte) (map[string]Database, error)
DatabasesFromSecrets finds DSNs in secrets and creates a map of databases.
Secret keys should be in the format FTL_DSN_<MODULENAME>_<DBNAME>
Types ¶
type Builder ¶
type Builder ModuleContext
Builder is used to build a ModuleContext
func NewBuilder ¶
NewBuilder creates a new blank Builder for the given module.
func NewBuilderFromContext ¶ added in v0.377.2
func NewBuilderFromContext(ctx ModuleContext) *Builder
func (*Builder) AddAllowedDirectVerb ¶ added in v0.377.2
func (b *Builder) AddAllowedDirectVerb(ref reflection.Ref) *Builder
AddAllowedDirectVerb adds a verb that can be called directly within the current context
func (*Builder) AddConfigs ¶
AddConfigs adds configuration values (as bytes) to the builder
func (*Builder) AddDatabases ¶
AddDatabases adds databases to the builder
func (*Builder) AddSecrets ¶
AddSecrets adds configuration values (as bytes) to the builder
func (*Builder) Build ¶
func (b *Builder) Build() ModuleContext
func (*Builder) UpdateForTesting ¶
func (b *Builder) UpdateForTesting(mockVerbs map[schema.RefKey]Verb, allowDirectVerbBehavior bool, leaseClient LeaseClient) *Builder
UpdateForTesting marks the builder as part of a test environment and adds mock verbs and flags for other test features.
type DBType ¶
type DBType ftlv1.ModuleContextResponse_DBType
type Database ¶
Database represents a database connection based on a DSN It holds a private field for the database which is accessible through moduleCtx.GetDatabase(name)
func NewDatabase ¶
NewDatabase creates a Database that can be added to ModuleContext
type DirectBehavior ¶
type DirectBehavior struct{}
DirectBehavior indicates that the verb should be executed by calling the function directly (for testing)
type DynamicModuleContext ¶ added in v0.264.2
type DynamicModuleContext struct {
// contains filtered or unexported fields
}
DynamicModuleContext provides up-to-date ModuleContext instances supplied by the controller
func FromContext ¶
func FromContext(ctx context.Context) *DynamicModuleContext
FromContext returns the DynamicModuleContext attached to a context.
func NewDynamicContext ¶ added in v0.264.2
func NewDynamicContext(ctx context.Context, supplier ModuleContextSupplier, moduleName string) (*DynamicModuleContext, error)
NewDynamicContext creates a new DynamicModuleContext. This operation blocks until the first ModuleContext is supplied by the controller.
The DynamicModuleContext will continually update as updated ModuleContext's are streamed from the controller. This operation may time out if the first module context is not supplied quickly enough (fixed at 5 seconds).
func (*DynamicModuleContext) ApplyToContext ¶ added in v0.264.2
func (m *DynamicModuleContext) ApplyToContext(ctx context.Context) context.Context
ApplyToContext returns a Go context.Context with DynamicModuleContext added.
func (*DynamicModuleContext) CurrentContext ¶ added in v0.264.2
func (m *DynamicModuleContext) CurrentContext() ModuleContext
CurrentContext immediately returns the most recently updated ModuleContext
type LeaseClient ¶ added in v0.224.0
type LeaseClient interface { // Returns ResourceExhausted if the lease is held. Acquire(ctx context.Context, module string, key []string, ttl time.Duration) error Heartbeat(ctx context.Context, module string, key []string, ttl time.Duration) error Release(ctx context.Context, key []string) error }
LeaseClient is the interface for acquiring, heartbeating and releasing leases
type MockBehavior ¶
type MockBehavior struct {
Mock Verb
}
MockBehavior indicates the verb has a mock implementation
type ModuleContext ¶
type ModuleContext struct {
// contains filtered or unexported fields
}
ModuleContext holds the context needed for a module, including configs, secrets and DSNs
ModuleContext is immutable
func Empty ¶ added in v0.248.0
func Empty(module string) ModuleContext
func FromProto ¶
func FromProto(response *ftlv1.ModuleContextResponse) (ModuleContext, error)
func (ModuleContext) BehaviorForVerb ¶
func (m ModuleContext) BehaviorForVerb(ref schema.Ref) (optional.Option[VerbBehavior], error)
BehaviorForVerb returns what to do to execute a verb
This allows module context to dictate behavior based on testing options Returning optional.Nil indicates the verb should be executed normally via the controller
func (ModuleContext) GetConfig ¶
func (m ModuleContext) GetConfig(name string, value any) error
GetConfig reads a configuration value for the module.
"value" must be a pointer to a Go type that can be unmarshalled from JSON.
func (ModuleContext) GetDatabase ¶
func (m ModuleContext) GetDatabase(name string, dbType DBType) (string, error)
GetDatabase gets a database DSN by name and type.
Returns an error if no database with that name is found or it is not the expected type. When in a testing context (via ftltest), an error is returned if the database is not a test database.
func (ModuleContext) GetSecret ¶
func (m ModuleContext) GetSecret(name string, value any) error
GetSecret reads a secret value for the module.
"value" must be a pointer to a Go type that can be unmarshalled from JSON.
func (ModuleContext) MockLeaseClient ¶ added in v0.224.0
func (m ModuleContext) MockLeaseClient() optional.Option[LeaseClient]
MockLeaseClient provides a mock lease client when testing
func (ModuleContext) ToProto ¶
func (m ModuleContext) ToProto() *ftlv1.ModuleContextResponse
ToProto converts a ModuleContext to a proto response.
type ModuleContextSupplier ¶ added in v0.264.2
type ModuleContextSupplier interface {
Subscribe(ctx context.Context, moduleName string, sink func(ctx context.Context, moduleContext ModuleContext), errorRetryCallback func(err error) bool)
}
func NewModuleContextSupplier ¶ added in v0.264.2
func NewModuleContextSupplier(client ftlv1connect.ModuleServiceClient) ModuleContextSupplier