path.go 453 B

123456789101112131415161718192021222324
  1. package sdkuri
  2. import (
  3. "path"
  4. "strings"
  5. )
  6. // PathJoin will join the elements of the path delimited by the "/"
  7. // character. Similar to path.Join with the exception the trailing "/"
  8. // character is preserved if present.
  9. func PathJoin(elems ...string) string {
  10. if len(elems) == 0 {
  11. return ""
  12. }
  13. hasTrailing := strings.HasSuffix(elems[len(elems)-1], "/")
  14. str := path.Join(elems...)
  15. if hasTrailing && str != "/" {
  16. str += "/"
  17. }
  18. return str
  19. }