This repository has been archived by the owner on Nov 11, 2023. It is now read-only.
/
message.go
74 lines (63 loc) · 1.95 KB
/
message.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
70
71
72
73
74
package kv
const ProtoVersion = "v9"
// Commands
const (
CmdProtoVersion = "version"
CmdReadKey = "kget"
CmdReadBulk = "kget-bulk"
CmdReadPrefix = "kget-all"
CmdWriteKey = "kset"
CmdWriteBulk = "kset-bulk"
CmdRemoveKey = "kdel"
CmdSubscribeKey = "ksub"
CmdSubscribePrefix = "ksub-prefix"
CmdUnsubscribeKey = "kunsub"
CmdUnsubscribePrefix = "kunsub-prefix"
CmdListKeys = "klist"
CmdAuthRequest = "klogin"
CmdAuthChallenge = "kauth"
CmdInternalClientID = "_uid"
)
type ErrCode string
const (
ErrServerError ErrCode = "server error"
ErrInvalidFmt ErrCode = "invalid message format"
ErrMissingParam ErrCode = "required parameter missing"
ErrUnknownCmd ErrCode = "unknown command"
ErrAuthNotInit ErrCode = "authentication not initialized"
ErrAuthFailed ErrCode = "authentication failed"
ErrAuthRequired ErrCode = "authentication required"
ErrAuthNotRequired ErrCode = "authentication not required"
ErrAuthNotSupported ErrCode = "authentication method not supported"
)
type AuthType string
const (
AuthTypeChallenge AuthType = "challenge"
AuthTypeInteractive AuthType = "ask"
)
type Request struct {
CmdName string `json:"command"`
RequestID string `json:"request_id,omitempty"`
Data map[string]interface{} `json:"data"`
}
type Error struct {
Ok bool `json:"ok"`
Error ErrCode `json:"error"`
Details string `json:"details"`
RequestID string `json:"request_id,omitempty"`
}
type Response struct {
CmdType string `json:"type"`
Ok bool `json:"ok"`
RequestID string `json:"request_id,omitempty"`
Data interface{} `json:"data,omitempty"`
}
type Push struct {
CmdType string `json:"type"`
Key string `json:"key"`
NewValue string `json:"new_value"`
}
type Hello struct {
CmdType string `json:"type"`
Version string `json:"version"`
}