forked from zabbix-tools/go-zabbix
-
Notifications
You must be signed in to change notification settings - Fork 2
/
request.go
50 lines (42 loc) · 1.52 KB
/
request.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
package zabbix
import (
"sync/atomic"
)
// A Request represents a JSON-RPC request to be sent by a client.
//
// This struct maps to the JSON request body described in the Zabbix API
// documentation:
// https://www.zabbix.com/documentation/2.2/manual/api#authentication.
type Request struct {
// JSONRPCVersion is the version string of the Zabbix API. This should
// always be set to "2.0".
JSONRPCVersion string `json:"jsonrpc"`
// Method is the name of the Zabbix API method to be called.
Method string `json:"method"`
// Params is the request's body.
Params interface{} `json:"params"`
// RequestID is an abitrary identifier for the Request which is returned in
// the corresponding API Response to assist with multi-threaded
// applications. This value is automatically incremented for each new
// Request by NewRequest.
RequestID uint64 `json:"id"`
// AuthToken is the Request's authentication token. When used in a Session,
// this value is overwritten by the Session.
AuthToken string `json:"auth,omitempty"`
}
// requestId is a global counter used to assign each APi request a unique ID.
var requestID uint64
// NewRequest returns a new Request given an API method name, and optional
// request body parameters.
func NewRequest(method string, params interface{}) *Request {
if params == nil {
params = map[string]string{}
}
return &Request{
JSONRPCVersion: "2.0",
Method: method,
Params: params,
RequestID: atomic.AddUint64(&requestID, 1),
AuthToken: "", // set by session
}
}