diff options
| author | Paul Buetow <paul@buetow.org> | 2026-07-08 23:17:39 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-07-08 23:17:39 +0300 |
| commit | 3f8b79f2b1384e3abc2b1bb2fe913688c7ec251c (patch) | |
| tree | 5cff57875a1f5b63536423c0b7fe7a3788ff15ac /internal/resource/multi.go | |
| parent | 920f2ea88c45e972cd87b56580c90a0277b7130e (diff) | |
add multi which can return multiple resources
Diffstat (limited to 'internal/resource/multi.go')
| -rw-r--r-- | internal/resource/multi.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/internal/resource/multi.go b/internal/resource/multi.go new file mode 100644 index 0000000..1694814 --- /dev/null +++ b/internal/resource/multi.go @@ -0,0 +1,39 @@ +package resource + +import ( + "errors" + "strings" +) + +// Multi is a collection of resources that satisfies the api.Resource interface. +type Multi []Resource + +func (m Multi) String() string { + strs := make([]string, 0, len(m)) + + for _, res := range m { + strs = append(strs, res.String()) + } + + return strings.Join(strs, ", ") +} + +func (m Multi) ID() string { + ids := make([]string, 0, len(m)) + + for _, res := range m { + ids = append(ids, res.String()) + } + + return strings.Join(ids, "+") +} + +func (m Multi) Apply() error { + var errs []error + + for _, res := range m { + errs = append(errs, res.Apply()) + } + + return errors.Join(errs...) +} |
