Skip to content

Commit

Permalink
make builders mutable so chaining not required
Browse files Browse the repository at this point in the history
  • Loading branch information
matt2e committed Apr 22, 2024
1 parent ae37ff5 commit bdf007f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions backend/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions common/modulecontext/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ 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{},
dsns: []dsnEntry{},
}
}

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}}
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
Expand Down

0 comments on commit bdf007f

Please sign in to comment.