Skip to content

Commit 8866d76

Browse files
linsitenemith
authored andcommitted
[doc] add more method docs
1 parent 81dc762 commit 8866d76

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

conn.go

+21
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,7 @@ func (c *Conn) request(opcode int32, req interface{}, res interface{}, recvFunc
936936
}
937937
}
938938

939+
// AddAuth adds an authentication config to the connection.
939940
func (c *Conn) AddAuth(scheme string, auth []byte) error {
940941
_, err := c.request(opSetAuth, &setAuthRequest{Type: 0, Scheme: scheme, Auth: auth}, &setAuthResponse{}, nil)
941942

@@ -962,6 +963,7 @@ func (c *Conn) AddAuth(scheme string, auth []byte) error {
962963
return nil
963964
}
964965

966+
// Children returns the children of a znode.
965967
func (c *Conn) Children(path string) ([]string, *Stat, error) {
966968
if err := validatePath(path, false); err != nil {
967969
return nil, nil, err
@@ -975,6 +977,7 @@ func (c *Conn) Children(path string) ([]string, *Stat, error) {
975977
return res.Children, &res.Stat, err
976978
}
977979

980+
// ChildrenW returns the children of a znode and sets a watch.
978981
func (c *Conn) ChildrenW(path string) ([]string, *Stat, <-chan Event, error) {
979982
if err := validatePath(path, false); err != nil {
980983
return nil, nil, nil, err
@@ -993,6 +996,7 @@ func (c *Conn) ChildrenW(path string) ([]string, *Stat, <-chan Event, error) {
993996
return res.Children, &res.Stat, ech, err
994997
}
995998

999+
// Get gets the contents of a znode.
9961000
func (c *Conn) Get(path string) ([]byte, *Stat, error) {
9971001
if err := validatePath(path, false); err != nil {
9981002
return nil, nil, err
@@ -1025,6 +1029,7 @@ func (c *Conn) GetW(path string) ([]byte, *Stat, <-chan Event, error) {
10251029
return res.Data, &res.Stat, ech, err
10261030
}
10271031

1032+
// Set updates the contents of a znode.
10281033
func (c *Conn) Set(path string, data []byte, version int32) (*Stat, error) {
10291034
if err := validatePath(path, false); err != nil {
10301035
return nil, err
@@ -1038,6 +1043,10 @@ func (c *Conn) Set(path string, data []byte, version int32) (*Stat, error) {
10381043
return &res.Stat, err
10391044
}
10401045

1046+
// Create creates a znode.
1047+
// The returned path is the new path assigned by the server, it may not be the
1048+
// same as the input, for example when creating a sequence znode the returned path
1049+
// will be the input path with a sequence number appended.
10411050
func (c *Conn) Create(path string, data []byte, flags int32, acl []ACL) (string, error) {
10421051
if err := validatePath(path, flags&FlagSequence == FlagSequence); err != nil {
10431052
return "", err
@@ -1051,6 +1060,7 @@ func (c *Conn) Create(path string, data []byte, flags int32, acl []ACL) (string,
10511060
return res.Path, err
10521061
}
10531062

1063+
// CreateContainer creates a container znode and returns the path.
10541064
func (c *Conn) CreateContainer(path string, data []byte, flags int32, acl []ACL) (string, error) {
10551065
if err := validatePath(path, flags&FlagSequence == FlagSequence); err != nil {
10561066
return "", err
@@ -1064,6 +1074,7 @@ func (c *Conn) CreateContainer(path string, data []byte, flags int32, acl []ACL)
10641074
return res.Path, err
10651075
}
10661076

1077+
// CreateTTL creates a TTL znode, which will be automatically deleted by server after the TTL.
10671078
func (c *Conn) CreateTTL(path string, data []byte, flags int32, acl []ACL, ttl time.Duration) (string, error) {
10681079
if err := validatePath(path, flags&FlagSequence == FlagSequence); err != nil {
10691080
return "", err
@@ -1126,6 +1137,7 @@ func (c *Conn) CreateProtectedEphemeralSequential(path string, data []byte, acl
11261137
return "", err
11271138
}
11281139

1140+
// Delete deletes a znode.
11291141
func (c *Conn) Delete(path string, version int32) error {
11301142
if err := validatePath(path, false); err != nil {
11311143
return err
@@ -1135,6 +1147,7 @@ func (c *Conn) Delete(path string, version int32) error {
11351147
return err
11361148
}
11371149

1150+
// Exists tells the existence of a znode.
11381151
func (c *Conn) Exists(path string) (bool, *Stat, error) {
11391152
if err := validatePath(path, false); err != nil {
11401153
return false, nil, err
@@ -1153,6 +1166,7 @@ func (c *Conn) Exists(path string) (bool, *Stat, error) {
11531166
return exists, &res.Stat, err
11541167
}
11551168

1169+
// ExistsW tells the existence of a znode and sets a watch.
11561170
func (c *Conn) ExistsW(path string) (bool, *Stat, <-chan Event, error) {
11571171
if err := validatePath(path, false); err != nil {
11581172
return false, nil, nil, err
@@ -1178,6 +1192,7 @@ func (c *Conn) ExistsW(path string) (bool, *Stat, <-chan Event, error) {
11781192
return exists, &res.Stat, ech, err
11791193
}
11801194

1195+
// GetACL gets the ACLs of a znode.
11811196
func (c *Conn) GetACL(path string) ([]ACL, *Stat, error) {
11821197
if err := validatePath(path, false); err != nil {
11831198
return nil, nil, err
@@ -1190,6 +1205,8 @@ func (c *Conn) GetACL(path string) ([]ACL, *Stat, error) {
11901205
}
11911206
return res.Acl, &res.Stat, err
11921207
}
1208+
1209+
// SetACL updates the ACLs of a znode.
11931210
func (c *Conn) SetACL(path string, acl []ACL, version int32) (*Stat, error) {
11941211
if err := validatePath(path, false); err != nil {
11951212
return nil, err
@@ -1203,6 +1220,9 @@ func (c *Conn) SetACL(path string, acl []ACL, version int32) (*Stat, error) {
12031220
return &res.Stat, err
12041221
}
12051222

1223+
// Sync flushes the channel between process and the leader of a given znode,
1224+
// you may need it if you want identical views of ZooKeeper data for 2 client instances.
1225+
// Please refer to the "Consistency Guarantees" section of ZK document for more details.
12061226
func (c *Conn) Sync(path string) (string, error) {
12071227
if err := validatePath(path, false); err != nil {
12081228
return "", err
@@ -1216,6 +1236,7 @@ func (c *Conn) Sync(path string) (string, error) {
12161236
return res.Path, err
12171237
}
12181238

1239+
// MultiResponse is the result of a Multi call.
12191240
type MultiResponse struct {
12201241
Stat *Stat
12211242
String string

0 commit comments

Comments
 (0)