-
Notifications
You must be signed in to change notification settings - Fork 39
/
types.go
36 lines (30 loc) · 814 Bytes
/
types.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
package zabbix
import "encoding/json"
type rpcRequest struct {
Jsonrpc string `json:"jsonrpc"`
Method string `json:"method"`
Params interface{} `json:"params"`
Auth string `json:"auth,omitempty"`
Id int `json:"id"`
}
type rpcResponse struct {
Jsonrpc string `json:"jsonrpc"`
Error zbxError `json:"error"`
Result interface{} `json:"result"`
Id int `json:"id"`
}
type zbxError struct {
Code int `json:"code"`
Message string `json:"message"`
Data string `json:"data"`
}
func (z *zbxError) Error() string {
return z.Data
}
func (r *rpcResponse) resultToBytes() ([]byte, bool, error) {
if result, ok := r.Result.(string); ok {
return []byte(result), true, nil
}
result, err := json.Marshal(r.Result)
return result, false, err
}