forked from fl00r/go-tarantool-1.6
-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathstorage_info.go
132 lines (109 loc) · 2.83 KB
/
storage_info.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package crud
import (
"context"
"github.com/vmihailenco/msgpack/v5"
"github.com/tarantool/go-tarantool/v2"
)
// StatusTable describes information for instance.
type StatusTable struct {
Status string
IsMaster bool
Message string
}
// DecodeMsgpack provides custom msgpack decoder.
func (statusTable *StatusTable) DecodeMsgpack(d *msgpack.Decoder) error {
l, err := d.DecodeMapLen()
if err != nil {
return err
}
for i := 0; i < l; i++ {
key, err := d.DecodeString()
if err != nil {
return err
}
switch key {
case "status":
if statusTable.Status, err = d.DecodeString(); err != nil {
return err
}
case "is_master":
if statusTable.IsMaster, err = d.DecodeBool(); err != nil {
return err
}
case "message":
if statusTable.Message, err = d.DecodeString(); err != nil {
return err
}
default:
if err := d.Skip(); err != nil {
return err
}
}
}
return nil
}
// StorageInfoResult describes result for `crud.storage_info` method.
type StorageInfoResult struct {
Info map[string]StatusTable
}
// DecodeMsgpack provides custom msgpack decoder.
func (r *StorageInfoResult) DecodeMsgpack(d *msgpack.Decoder) error {
_, err := d.DecodeArrayLen()
if err != nil {
return err
}
l, err := d.DecodeMapLen()
if err != nil {
return err
}
info := make(map[string]StatusTable)
for i := 0; i < l; i++ {
key, err := d.DecodeString()
if err != nil {
return err
}
statusTable := StatusTable{}
if err := d.Decode(&statusTable); err != nil {
return nil
}
info[key] = statusTable
}
r.Info = info
return nil
}
// StorageInfoOpts describes options for `crud.storage_info` method.
type StorageInfoOpts = BaseOpts
// StorageInfoRequest helps you to create request object to call
// `crud.storage_info` for execution by a Connection.
type StorageInfoRequest struct {
baseRequest
opts StorageInfoOpts
}
type storageInfoArgs struct {
_msgpack struct{} `msgpack:",asArray"` //nolint: structcheck,unused
Opts StorageInfoOpts
}
// MakeStorageInfoRequest returns a new empty StorageInfoRequest.
func MakeStorageInfoRequest() StorageInfoRequest {
req := StorageInfoRequest{}
req.impl = newCall("crud.storage_info")
req.opts = StorageInfoOpts{}
return req
}
// Opts sets the options for the torageInfoRequest request.
// Note: default value is nil.
func (req StorageInfoRequest) Opts(opts StorageInfoOpts) StorageInfoRequest {
req.opts = opts
return req
}
// Body fills an encoder with the call request body.
func (req StorageInfoRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error {
args := storageInfoArgs{Opts: req.opts}
req.impl = req.impl.Args(args)
return req.impl.Body(res, enc)
}
// Context sets a passed context to CRUD request.
func (req StorageInfoRequest) Context(ctx context.Context) StorageInfoRequest {
req.impl = req.impl.Context(ctx)
return req
}