modulecontext

package
v0.199.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

Variables

This section is empty.

Functions

This section is empty.

Types

type DBType

func (DBType) String

func (x DBType) String() string

type Database added in v0.196.1

type Database struct {
	DSN    string
	DBType DBType
	// contains filtered or unexported fields
}

func NewDatabase added in v0.196.1

func NewDatabase(dbType DBType, dsn string) (Database, error)

NewDatabase creates a Database that can be added to ModuleContext

type DirectBehavior added in v0.196.0

type DirectBehavior struct{}

DirectBehavior indicates that the verb should be executed by calling the function directly (for testing)

type MockBehavior added in v0.196.0

type MockBehavior struct {
	Mock MockVerb
}

MockBehavior indicates the verb has a mock implementation

type MockVerb added in v0.196.0

type MockVerb func(ctx context.Context, req any) (resp any, err error)

type ModuleContext

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

ModuleContext holds the context needed for a module, including configs, secrets and DSNs

func FromContext added in v0.196.0

func FromContext(ctx context.Context) ModuleContext

FromContext returns the ModuleContext attached to a context.

func FromProto added in v0.185.0

func FromProto(response *ftlv1.ModuleContextResponse) (ModuleContext, error)

func New added in v0.185.0

func New(module string) ModuleContext

New creates a new blank ModuleContext for the given module.

func (ModuleContext) ApplyToContext

func (m ModuleContext) ApplyToContext(ctx context.Context) context.Context

ApplyToContext returns a Go context.Context with ModuleContext added.

func (ModuleContext) BehaviorForVerb added in v0.196.0

func (m ModuleContext) BehaviorForVerb(ref schema.Ref) (VerbBehavior, error)

BehaviorForVerb returns what to do to execute a verb

This allows module context to dictate behavior based on testing options

func (ModuleContext) GetConfig added in v0.196.0

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 added in v0.196.0

func (m ModuleContext) GetDatabase(name string, dbType DBType) (*sql.DB, error)

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 added in v0.196.0

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 added in v0.185.0

ToProto converts a ModuleContext to a proto response.

func (ModuleContext) Update added in v0.196.1

func (m ModuleContext) Update(configs map[string][]byte, secrets map[string][]byte, databases map[string]Database) ModuleContext

Update copies a ModuleContext and adds configs, secrets and databases.

func (ModuleContext) UpdateForTesting added in v0.196.1

func (m ModuleContext) UpdateForTesting(mockVerbs map[schema.RefKey]MockVerb, allowDirectVerbBehavior bool) ModuleContext

UpdateForTesting copies a ModuleContext and marks it as part of a test environment and adds mock verbs and flags for other test features.

func (ModuleContext) UpdateFromEnvironment added in v0.196.1

func (m ModuleContext) UpdateFromEnvironment(ctx context.Context) (ModuleContext, error)

UpdateFromEnvironment copies a ModuleContext and gathers configs, secrets and databases from the local environment.

This is useful for testing and development, where the environment is used to provide configurations, secrets and DSNs. The context is built from a combination of the ftl-project.toml file and (for now) environment variables.

type StandardBehavior added in v0.196.0

type StandardBehavior struct{}

StandardBehavior indicates that the verb should be executed via the controller

type VerbBehavior added in v0.196.0

type VerbBehavior interface {
	// contains filtered or unexported methods
}

VerbBehavior indicates how to execute a verb

Jump to

Keyboard shortcuts

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