-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
apiarg.go
53 lines (46 loc) · 1.19 KB
/
apiarg.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
package libkb
import (
"net/url"
"time"
)
type APISessionType int
const (
APISessionTypeNONE APISessionType = 0
APISessionTypeOPTIONAL APISessionType = 1
APISessionTypeREQUIRED APISessionType = 2
)
type APIHeader struct {
Key string
Value string
}
type APIArg struct {
Endpoint string
uArgs url.Values
Args HTTPArgs
JSONPayload JSONPayload
SessionType APISessionType
HTTPStatus []int
AppStatusCodes []int
InitialTimeout time.Duration // optional
RetryMultiplier float64 // optional
RetryCount int // optional
UseText bool
}
// NewAPIArg creates a standard APIArg that will result
// in one API request with the default timeout.
func NewAPIArg(endpoint string) APIArg {
return APIArg{
Endpoint: endpoint,
}
}
// NewRetryAPIArg creates an APIArg that will cause the http client
// to use a much smaller request timeout, but retry the request
// several times, backing off on the timeout each time.
func NewRetryAPIArg(endpoint string) APIArg {
return APIArg{
Endpoint: endpoint,
InitialTimeout: HTTPRetryInitialTimeout,
RetryMultiplier: HTTPRetryMutliplier,
RetryCount: HTTPRetryCount,
}
}