From 19290795eccd0ec204c2e6cc1827d12b69de4c00 Mon Sep 17 00:00:00 2001 From: Matt Toohey Date: Mon, 22 Apr 2024 13:04:39 +1000 Subject: [PATCH] make builders mutable so chaining not required --- backend/controller/controller.go | 6 +++--- common/modulecontext/builder.go | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/backend/controller/controller.go b/backend/controller/controller.go index 9c4e8fe922..52a56f6cb3 100644 --- a/backend/controller/controller.go +++ b/backend/controller/controller.go @@ -659,9 +659,9 @@ func (s *Service) GetModuleContext(ctx context.Context, req *connect.Request[ftl } b := modulecontext.NewBuilder(req.Msg.Module) - b = b.AddConfigFromManager(configuration.ConfigFromContext(ctx)) - b = b.AddSecretsFromManager(configuration.SecretsFromContext(ctx)) - b = b.AddDSNsFromEnvarsForModule(schemas[0]) + b.AddConfigFromManager(configuration.ConfigFromContext(ctx)) + b.AddSecretsFromManager(configuration.SecretsFromContext(ctx)) + b.AddDSNsFromEnvarsForModule(schemas[0]) moduleCtx, err := b.Build(ctx) if err != nil { return nil, err diff --git a/common/modulecontext/builder.go b/common/modulecontext/builder.go index bf3bce51b2..d5be67becd 100644 --- a/common/modulecontext/builder.go +++ b/common/modulecontext/builder.go @@ -66,8 +66,8 @@ type Builder struct { dsns []dsnEntry } -func NewBuilder(moduleName string) Builder { - return Builder{ +func NewBuilder(moduleName string) *Builder { + return &Builder{ moduleName: moduleName, configs: []configOrSecretItem{}, secrets: []configOrSecretItem{}, @@ -75,8 +75,8 @@ func NewBuilder(moduleName string) Builder { } } -func NewBuilderFromProto(moduleName string, response *ftlv1.ModuleContextResponse) Builder { - return Builder{ +func NewBuilderFromProto(moduleName string, response *ftlv1.ModuleContextResponse) *Builder { + return &Builder{ moduleName: moduleName, configs: slices.Map(response.Configs, func(c *ftlv1.ModuleContextResponse_Config) configOrSecretItem { return refValuePair{ref: refFromProto(c.Ref), resolver: dataResolver{data: c.Data}} @@ -90,7 +90,7 @@ func NewBuilderFromProto(moduleName string, response *ftlv1.ModuleContextRespons } } -func (b Builder) Build(ctx context.Context) (*ModuleContext, error) { +func (b *Builder) Build(ctx context.Context) (*ModuleContext, error) { cm, err := newInMemoryConfigManager[cf.Configuration](ctx) if err != nil { return nil, err @@ -135,7 +135,7 @@ func newInMemoryConfigManager[R cf.Role](ctx context.Context) (*cf.Manager[R], e return manager, nil } -func buildConfigOrSecrets[R cf.Role](ctx context.Context, b Builder, manager cf.Manager[R], items []configOrSecretItem) error { +func buildConfigOrSecrets[R cf.Role](ctx context.Context, b *Builder, manager cf.Manager[R], items []configOrSecretItem) error { for _, item := range items { switch item := item.(type) { case refValuePair: @@ -174,7 +174,7 @@ func buildConfigOrSecrets[R cf.Role](ctx context.Context, b Builder, manager cf. return nil } -func (b Builder) AddDSNsFromEnvarsForModule(module *schema.Module) Builder { +func (b *Builder) AddDSNsFromEnvarsForModule(module *schema.Module) *Builder { // remove in favor of a non-envar approach once it is available for _, decl := range module.Decls { dbDecl, ok := decl.(*schema.Database) @@ -192,12 +192,12 @@ func (b Builder) AddDSNsFromEnvarsForModule(module *schema.Module) Builder { return b } -func (b Builder) AddConfigFromManager(cm *cf.Manager[cf.Configuration]) Builder { +func (b *Builder) AddConfigFromManager(cm *cf.Manager[cf.Configuration]) *Builder { b.configs = append(b.configs, configManager[cf.Configuration]{manager: cm}) return b } -func (b Builder) AddSecretsFromManager(sm *cf.Manager[cf.Secrets]) Builder { +func (b *Builder) AddSecretsFromManager(sm *cf.Manager[cf.Secrets]) *Builder { b.secrets = append(b.secrets, configManager[cf.Secrets]{manager: sm}) return b }