-
Notifications
You must be signed in to change notification settings - Fork 0
/
path.go
41 lines (35 loc) · 880 Bytes
/
path.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package client
import (
"path"
"strings"
)
func isRoot(key string) bool {
return key == "/"
}
func checkRootKey(rootKey string) bool {
return !strings.Contains(rootKey, "/")
//return rootKey != "" && !strings.HasSuffix(rootKey, "/")
}
// ensure key, return (realKey, parentKey)
func (clt *EtcdHRCHYClient) ensureKey(key string) (r1 string, r2 string, err error) {
//if !strings.HasPrefix(key, "/") {
// return "", "", ErrorInvalidKey
//}
if isRoot(key) {
return "/", "/", nil
//return clt.rootKey, clt.rootKey, nil
} else {
realKey := WithRootKey(clt.rootKey, key)
return realKey, path.Clean(realKey + "/../"), nil
}
}
func WithRootKey(rootKey, key string) string {
key = strings.Trim(key, "/")
//key = strings.TrimPrefix(key, "/")
//key = strings.TrimSuffix(key, "/")
ret := rootKey + "/" + key
if rootKey != "" {
ret = "/" + ret
}
return ret
}