This repository has been archived by the owner on Oct 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 94
/
zk.go
69 lines (65 loc) · 2.18 KB
/
zk.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2016 CoreOS, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package zetcd
import "fmt"
// ZK is a synchronous interface
type ZK interface {
Create(xid Xid, op *CreateRequest) ZKResponse
Delete(xid Xid, op *DeleteRequest) ZKResponse
Exists(xid Xid, op *ExistsRequest) ZKResponse
GetData(xid Xid, op *GetDataRequest) ZKResponse
SetData(xid Xid, op *SetDataRequest) ZKResponse
GetAcl(xid Xid, op *GetAclRequest) ZKResponse
SetAcl(xid Xid, op *SetAclRequest) ZKResponse
GetChildren(xid Xid, op *GetChildrenRequest) ZKResponse
Sync(xid Xid, op *SyncRequest) ZKResponse
Ping(xid Xid, op *PingRequest) ZKResponse
GetChildren2(xid Xid, op *GetChildren2Request) ZKResponse
// opCheck = 13
Multi(xid Xid, op *MultiRequest) ZKResponse
Close(xid Xid, op *CloseRequest) ZKResponse
SetAuth(xid Xid, op *SetAuthRequest) ZKResponse
SetWatches(xid Xid, op *SetWatchesRequest) ZKResponse
}
func DispatchZK(zk ZK, xid Xid, op interface{}) ZKResponse {
switch op := op.(type) {
case *CreateRequest:
return zk.Create(xid, op)
case *DeleteRequest:
return zk.Delete(xid, op)
case *GetChildrenRequest:
return zk.GetChildren(xid, op)
case *GetChildren2Request:
return zk.GetChildren2(xid, op)
case *PingRequest:
return zk.Ping(xid, op)
case *GetDataRequest:
return zk.GetData(xid, op)
case *SetDataRequest:
return zk.SetData(xid, op)
case *ExistsRequest:
return zk.Exists(xid, op)
case *SyncRequest:
return zk.Sync(xid, op)
case *CloseRequest:
return zk.Close(xid, op)
case *SetWatchesRequest:
return zk.SetWatches(xid, op)
case *MultiRequest:
return zk.Multi(xid, op)
default:
fmt.Printf("unexpected type %d %T\n", xid, op)
}
return mkZKErr(xid, 0, errAPIError)
}