-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil.go
53 lines (43 loc) · 937 Bytes
/
util.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
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2018-2019 The vogo Authors. All rights reserved.
// author: wongoo
// since: 2018/12/27
//
package zkclient
import (
"strings"
"github.com/samuel/go-zookeeper/zk"
)
// StateAlive whether zk state alive
func StateAlive(state zk.State) bool {
switch state {
case zk.StateDisconnected, zk.StateAuthFailed, zk.StateConnecting:
return false
}
return true
}
func IsZKInvalidErr(err error) bool {
switch err {
case zk.ErrInvalidACL, zk.ErrInvalidPath:
return true
default:
return false
}
}
func IsZKRecoverableErr(err error) bool {
switch err {
case zk.ErrClosing, zk.ErrConnectionClosed, zk.ErrSessionExpired, zk.ErrSessionMoved, zk.ErrNoServer:
return true
default:
return false
}
}
func ParentNode(path string) string {
idx := strings.LastIndex(path, PathSplit)
if idx > 0 {
return path[:idx]
}
return ""
}
func PathJoin(nodes ...string) string {
return strings.Join(nodes, PathSplit)
}