helpers.go 965 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package store
  2. import (
  3. "strings"
  4. )
  5. // CreateEndpoints creates a list of endpoints given the right scheme
  6. func CreateEndpoints(addrs []string, scheme string) (entries []string) {
  7. for _, addr := range addrs {
  8. entries = append(entries, scheme+"://"+addr)
  9. }
  10. return entries
  11. }
  12. // Normalize the key for each store to the form:
  13. //
  14. // /path/to/key
  15. //
  16. func Normalize(key string) string {
  17. return "/" + join(SplitKey(key))
  18. }
  19. // GetDirectory gets the full directory part of
  20. // the key to the form:
  21. //
  22. // /path/to/
  23. //
  24. func GetDirectory(key string) string {
  25. parts := SplitKey(key)
  26. parts = parts[:len(parts)-1]
  27. return "/" + join(parts)
  28. }
  29. // SplitKey splits the key to extract path informations
  30. func SplitKey(key string) (path []string) {
  31. if strings.Contains(key, "/") {
  32. path = strings.Split(key, "/")
  33. } else {
  34. path = []string{key}
  35. }
  36. return path
  37. }
  38. // join the path parts with '/'
  39. func join(parts []string) string {
  40. return strings.Join(parts, "/")
  41. }