Skip to content

Commit 7039b08

Browse files
authored
fix: use maps package for copying (#411)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 6e07d2b commit 7039b08

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

pkgmgr/pkgmgr.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"errors"
1919
"fmt"
2020
"io"
21+
"maps"
2122
"os"
2223
"path/filepath"
2324
"strings"
@@ -183,9 +184,7 @@ func (p *PackageManager) Install(pkgs ...string) error {
183184
)
184185
// Build package options
185186
tmpPkgOpts := installPkg.Install.defaultOpts()
186-
for k, v := range installPkg.Options {
187-
tmpPkgOpts[k] = v
188-
}
187+
maps.Copy(tmpPkgOpts, installPkg.Options)
189188
// Install package
190189
notes, outputs, err := installPkg.Install.install(
191190
p.config,
@@ -660,9 +659,7 @@ func (p *PackageManager) updateContext(name string, newContext Context) error {
660659
func (p *PackageManager) ContextEnv() map[string]string {
661660
ret := make(map[string]string)
662661
for _, pkg := range p.InstalledPackages() {
663-
for k, v := range pkg.Outputs {
664-
ret[k] = v
665-
}
662+
maps.Copy(ret, pkg.Outputs)
666663
}
667664
return ret
668665
}

pkgmgr/template.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package pkgmgr
1717
import (
1818
"bytes"
1919
"fmt"
20+
"maps"
2021
"text/template"
2122

2223
"github.com/Masterminds/sprig/v3"
@@ -40,12 +41,8 @@ func (t *Template) Render(
4041
) (string, error) {
4142
// Build our vars
4243
tmpVars := map[string]any{}
43-
for k, v := range t.baseVars {
44-
tmpVars[k] = v
45-
}
46-
for k, v := range extraVars {
47-
tmpVars[k] = v
48-
}
44+
maps.Copy(tmpVars, t.baseVars)
45+
maps.Copy(tmpVars, extraVars)
4946
// Parse template body
5047
tmpl, err := t.tmpl.Parse(tmplBody)
5148
if err != nil {
@@ -62,12 +59,8 @@ func (t *Template) Render(
6259
// WithVars creates a copy of the Template with the extra variables added to the original base variables
6360
func (t *Template) WithVars(extraVars map[string]any) *Template {
6461
tmpVars := map[string]any{}
65-
for k, v := range t.baseVars {
66-
tmpVars[k] = v
67-
}
68-
for k, v := range extraVars {
69-
tmpVars[k] = v
70-
}
62+
maps.Copy(tmpVars, t.baseVars)
63+
maps.Copy(tmpVars, extraVars)
7164
tmpl := NewTemplate(tmpVars)
7265
return tmpl
7366
}

0 commit comments

Comments
 (0)