github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/libkb/apiarg.go (about) 1 package libkb 2 3 import ( 4 "net/url" 5 "time" 6 ) 7 8 type APISessionType int 9 10 const ( 11 APISessionTypeNONE APISessionType = 0 12 APISessionTypeOPTIONAL APISessionType = 1 13 APISessionTypeREQUIRED APISessionType = 2 14 ) 15 16 type APIHeader struct { 17 Key string 18 Value string 19 } 20 21 type APIArg struct { 22 Endpoint string 23 uArgs url.Values 24 Args HTTPArgs 25 JSONPayload JSONPayload 26 SessionType APISessionType 27 HTTPStatus []int 28 AppStatusCodes []int 29 InitialTimeout time.Duration // optional 30 RetryMultiplier float64 // optional 31 RetryCount int // optional 32 UseText bool 33 } 34 35 // NewAPIArg creates a standard APIArg that will result 36 // in one API request with the default timeout. 37 func NewAPIArg(endpoint string) APIArg { 38 return APIArg{ 39 Endpoint: endpoint, 40 } 41 } 42 43 // NewRetryAPIArg creates an APIArg that will cause the http client 44 // to use a much smaller request timeout, but retry the request 45 // several times, backing off on the timeout each time. 46 func NewRetryAPIArg(endpoint string) APIArg { 47 return APIArg{ 48 Endpoint: endpoint, 49 InitialTimeout: HTTPRetryInitialTimeout, 50 RetryMultiplier: HTTPRetryMutliplier, 51 RetryCount: HTTPRetryCount, 52 } 53 }