modulecontext

package
v0.202.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

Variables

This section is empty.

Functions

func DatabasesFromEnvironment

func DatabasesFromEnvironment(ctx context.Context, module string) (map[string]Database, error)

DatabasesFromEnvironment finds DSNs in environment variables and creates a map of databases.

Types

type Builder

type Builder ModuleContext

Builder is used to build a ModuleContext

func NewBuilder

func NewBuilder(module string) *Builder

NewBuilder creates a new blank Builder for the given module.

func (*Builder) AddConfigs

func (b *Builder) AddConfigs(configs map[string][]byte) *Builder

AddConfigs adds configuration values (as bytes) to the builder

func (*Builder) AddDatabases

func (b *Builder) AddDatabases(databases map[string]Database) *Builder

AddDatabases adds databases to the builder

func (*Builder) AddSecrets

func (b *Builder) AddSecrets(secrets map[string][]byte) *Builder

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]MockVerb, allowDirectVerbBehavior bool) *Builder

UpdateForTesting marks the builder as part of a test environment and adds mock verbs and flags for other test features.

type DBType

func (DBType) String

func (x DBType) String() string

type Database

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

func NewDatabase

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

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 MockBehavior

type MockBehavior struct {
	Mock MockVerb
}

MockBehavior indicates the verb has a mock implementation

type MockVerb

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

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) (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

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) (*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

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

ToProto converts a ModuleContext to a proto response.

type StandardBehavior

type StandardBehavior struct{}

StandardBehavior indicates that the verb should be executed via the controller

type VerbBehavior

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