You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

util.go 1.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. Copyright 2021 The KubeEdge Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package util
  14. import (
  15. "fmt"
  16. "os"
  17. "strings"
  18. )
  19. // FileIsExist check file is exist
  20. func FileIsExist(path string) bool {
  21. _, err := os.Stat(path)
  22. if err == nil {
  23. return true
  24. }
  25. return os.IsExist(err)
  26. }
  27. func SpliceErrors(errors []error) string {
  28. if len(errors) == 0 {
  29. return ""
  30. }
  31. var stb strings.Builder
  32. stb.WriteString("[\n")
  33. for _, err := range errors {
  34. stb.WriteString(fmt.Sprintf(" %s\n", err.Error()))
  35. }
  36. stb.WriteString("]\n")
  37. return stb.String()
  38. }