From fab70472af3c4057f2e12019ae6bde1e1c2d013b Mon Sep 17 00:00:00 2001 From: joemicky Date: Thu, 14 Aug 2025 19:21:52 +0800 Subject: [PATCH] refactor: replace []byte(fmt.Sprintf) with fmt.Appendf Signed-off-by: joemicky --- internal/chart/v3/util/create.go | 4 ++-- pkg/chart/v2/util/create.go | 4 ++-- pkg/registry/utils_test.go | 2 +- pkg/repo/repotest/server.go | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/chart/v3/util/create.go b/internal/chart/v3/util/create.go index 72fed5955..6a28f99d4 100644 --- a/internal/chart/v3/util/create.go +++ b/internal/chart/v3/util/create.go @@ -733,12 +733,12 @@ func Create(name, dir string) (string, error) { { // Chart.yaml path: filepath.Join(cdir, ChartfileName), - content: []byte(fmt.Sprintf(defaultChartfile, name)), + content: fmt.Appendf(nil, defaultChartfile, name), }, { // values.yaml path: filepath.Join(cdir, ValuesfileName), - content: []byte(fmt.Sprintf(defaultValues, name)), + content: fmt.Appendf(nil, defaultValues, name), }, { // .helmignore diff --git a/pkg/chart/v2/util/create.go b/pkg/chart/v2/util/create.go index e9cf3c2c6..a8ae3ab40 100644 --- a/pkg/chart/v2/util/create.go +++ b/pkg/chart/v2/util/create.go @@ -733,12 +733,12 @@ func Create(name, dir string) (string, error) { { // Chart.yaml path: filepath.Join(cdir, ChartfileName), - content: []byte(fmt.Sprintf(defaultChartfile, name)), + content: fmt.Appendf(nil, defaultChartfile, name), }, { // values.yaml path: filepath.Join(cdir, ValuesfileName), - content: []byte(fmt.Sprintf(defaultValues, name)), + content: fmt.Appendf(nil, defaultValues, name), }, { // .helmignore diff --git a/pkg/registry/utils_test.go b/pkg/registry/utils_test.go index f4ff5bd58..b46317fc6 100644 --- a/pkg/registry/utils_test.go +++ b/pkg/registry/utils_test.go @@ -121,7 +121,7 @@ func setup(suite *TestSuite, tlsEnabled, insecure bool) *registry.Registry { pwBytes, err := bcrypt.GenerateFromPassword([]byte(testPassword), bcrypt.DefaultCost) suite.Nil(err, "no error generating bcrypt password for test htpasswd file") htpasswdPath := filepath.Join(suite.WorkspaceDir, testHtpasswdFileBasename) - err = os.WriteFile(htpasswdPath, []byte(fmt.Sprintf("%s:%s\n", testUsername, string(pwBytes))), 0644) + err = os.WriteFile(htpasswdPath, fmt.Appendf(nil, "%s:%s\n", testUsername, string(pwBytes)), 0644) suite.Nil(err, "no error creating test htpasswd file") // Registry config diff --git a/pkg/repo/repotest/server.go b/pkg/repo/repotest/server.go index 7ff028b90..8f9f82281 100644 --- a/pkg/repo/repotest/server.go +++ b/pkg/repo/repotest/server.go @@ -169,7 +169,7 @@ func NewOCIServer(t *testing.T, dir string) (*OCIServer, error) { t.Fatal("error generating bcrypt password for test htpasswd file") } htpasswdPath := filepath.Join(dir, testHtpasswdFileBasename) - err = os.WriteFile(htpasswdPath, []byte(fmt.Sprintf("%s:%s\n", testUsername, string(pwBytes))), 0o644) + err = os.WriteFile(htpasswdPath, fmt.Appendf(nil, "%s:%s\n", testUsername, string(pwBytes)), 0o644) if err != nil { t.Fatalf("error creating test htpasswd file") }