Skip to content

Commit 3975f02

Browse files
liuyueyangxmundeloof
authored andcommitted
refactor: use strings.Builder to improve performance
Signed-off-by: liuyueyangxmu <[email protected]>
1 parent fa832d7 commit 3975f02

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

pkg/compose/publish.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,13 @@ func (s *composeService) checkEnvironmentVariables(project *types.Project, optio
388388
if !options.WithEnvironment && len(errorList) > 0 {
389389
errorMsgSuffix := "To avoid leaking sensitive data, you must either explicitly allow the sending of environment variables by using the --with-env flag,\n" +
390390
"or remove sensitive data from your Compose configuration"
391-
errorMsg := ""
391+
var errorMsg strings.Builder
392392
for _, errors := range errorList {
393393
for _, err := range errors {
394-
errorMsg += fmt.Sprintf("%s\n", err)
394+
errorMsg.WriteString(fmt.Sprintf("%s\n", err))
395395
}
396396
}
397-
return nil, fmt.Errorf("%s%s", errorMsg, errorMsgSuffix)
397+
return nil, fmt.Errorf("%s%s", errorMsg.String(), errorMsgSuffix)
398398

399399
}
400400
return envVarList, nil
@@ -422,11 +422,12 @@ func (s *composeService) checkOnlyBuildSection(project *types.Project) (bool, er
422422
}
423423
}
424424
if len(errorList) > 0 {
425-
errMsg := "your Compose stack cannot be published as it only contains a build section for service(s):\n"
425+
var errMsg strings.Builder
426+
errMsg.WriteString("your Compose stack cannot be published as it only contains a build section for service(s):\n")
426427
for _, serviceInError := range errorList {
427-
errMsg += fmt.Sprintf("- %q\n", serviceInError)
428+
errMsg.WriteString(fmt.Sprintf("- %q\n", serviceInError))
428429
}
429-
return false, errors.New(errMsg)
430+
return false, errors.New(errMsg.String())
430431
}
431432
return true, nil
432433
}

0 commit comments

Comments
 (0)