-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.go
44 lines (36 loc) · 908 Bytes
/
options.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
package api
import (
"time"
"golang.org/x/time/rate"
)
// RequestOption -
type RequestOption func(*Request)
// WithCustomID - set custom request id. Request id increment automatically per request.
func WithCustomID(id uint64) RequestOption {
return func(req *Request) {
req.ID = id
}
}
// WithJsonRpcVersion - change json rpc version. Default: 2.0
func WithJsonRpcVersion(version string) RequestOption {
return func(req *Request) {
req.Version = version
}
}
// ApiOption -
type ApiOption func(*API)
// WithRateLimit -
func WithRateLimit(requestPerSecond int) ApiOption {
return func(api *API) {
if requestPerSecond > 0 {
api.rateLimit = rate.NewLimiter(rate.Every(time.Second/time.Duration(requestPerSecond)), requestPerSecond)
}
}
}
// WithApiKey -
func WithApiKey(header, apiKey string) ApiOption {
return func(api *API) {
api.headerApiKey = header
api.apiKey = apiKey
}
}