Documentation ¶
Index ¶
- Constants
- func DatabasesFromEnvironment(ctx context.Context, module string) (map[string]Database, error)
- type 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 MockBehavior
- type ModuleContext
- func (m ModuleContext) ApplyToContext(ctx context.Context) context.Context
- 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) (*sql.DB, error)
- func (m ModuleContext) GetSecret(name string, value any) error
- func (m ModuleContext) ToProto() *ftlv1.ModuleContextResponse
- type Verb
- type VerbBehavior
Constants ¶
const (
DBTypePostgres = DBType(ftlv1.ModuleContextResponse_POSTGRES)
)
Variables ¶
This section is empty.
Functions ¶
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 (*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
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)
type DirectBehavior ¶
type DirectBehavior struct{}
DirectBehavior indicates that the verb should be executed by calling the function directly (for testing)
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 FromContext ¶
func FromContext(ctx context.Context) ModuleContext
FromContext returns the ModuleContext attached to a context.
func FromProto ¶
func FromProto(response *ftlv1.ModuleContextResponse) (ModuleContext, error)
func (ModuleContext) ApplyToContext ¶
func (m ModuleContext) ApplyToContext(ctx context.Context) context.Context
ApplyToContext returns a Go context.Context with ModuleContext added.
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 ¶
GetDatabase gets a database connection
Returns an error if no database with that name is found or it is not the expected type
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) ToProto ¶
func (m ModuleContext) ToProto() *ftlv1.ModuleContextResponse
ToProto converts a ModuleContext to a proto response.