generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: module context should be immutable
- Loading branch information
Showing
11 changed files
with
181 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
package modulecontext | ||
|
||
import ( | ||
"fmt" | ||
|
||
ftlv1 "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1" | ||
) | ||
|
||
func FromProto(response *ftlv1.ModuleContextResponse) (*ModuleContext, error) { | ||
moduleCtx := New(response.Module) | ||
for name, data := range response.Configs { | ||
moduleCtx.configs[name] = data | ||
} | ||
for name, data := range response.Secrets { | ||
moduleCtx.secrets[name] = data | ||
} | ||
for _, entry := range response.Databases { | ||
if err := moduleCtx.AddDatabase(entry.Name, DBType(entry.Type), entry.Dsn); err != nil { | ||
return nil, err | ||
func FromProto(response *ftlv1.ModuleContextResponse) (ModuleContext, error) { | ||
databases := map[string]Database{} | ||
for name, entry := range response.Databases { | ||
db, err := NewDatabase(DBType(entry.Type), entry.Dsn) | ||
if err != nil { | ||
return ModuleContext{}, fmt.Errorf("could not create database %q with DSN %q: %w", name, entry.Dsn, err) | ||
} | ||
databases[entry.Name] = db | ||
} | ||
return moduleCtx, nil | ||
return New(response.Module).Update(response.Configs, response.Secrets, databases), nil | ||
} |
Oops, something went wrong.