-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatamanager.go
More file actions
36 lines (30 loc) · 884 Bytes
/
datamanager.go
File metadata and controls
36 lines (30 loc) · 884 Bytes
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 libdatamanager
// LibDM data required in all requests
type LibDM struct {
Config *RequestConfig
MaxConnectionsPerHost int
}
// NewLibDM create new libDM "class"
func NewLibDM(config *RequestConfig) *LibDM {
return &LibDM{
Config: config,
}
}
// WithMaxConnections per host
func (libdm *LibDM) WithMaxConnections(maxConnecetions int) *LibDM {
libdm.MaxConnectionsPerHost = maxConnecetions
return libdm
}
// Request do a request using libdm
func (libdm LibDM) Request(ep Endpoint, payload, response interface{}, authorized bool) (*RestRequestResponse, error) {
req := libdm.NewRequest(ep, payload)
req.WithConnectionLimit(libdm.MaxConnectionsPerHost)
if authorized {
req.WithAuthFromConfig()
}
resp, err := req.Do(response)
if err != nil || resp.Status == ResponseError {
return nil, NewErrorFromResponse(resp, err)
}
return resp, nil
}