Documentation
¶
Overview ¶
Package utils //
Package utils //
Package utils //
Index ¶
- func GetBoolValue(value interface{}) (bool, error)
- func GetFloatValue(value interface{}) (float64, error)
- func GetIntValue(value interface{}) (int64, error)
- func GetStringValue(value interface{}) (string, error)
- func Headers(headers ...Header) func(r *HTTPRequester)
- func Retries(retries int) func(r *HTTPRequester)
- func Timeout(timeout time.Duration) func(r *HTTPRequester)
- type CancelableExecutionCtx
- type ExecutionCtx
- type HTTPRequester
- func (r HTTPRequester) Do(method string, body io.Reader, headers []Header) (response []byte, code int, err error)
- func (r HTTPRequester) Get(headers ...Header) (response []byte, code int, err error)
- func (r HTTPRequester) GetObj(result interface{}, headers ...Header) error
- func (r HTTPRequester) Post(body interface{}, headers ...Header) (response []byte, code int, err error)
- func (r HTTPRequester) PostObj(body, result interface{}, headers ...Header) error
- func (r HTTPRequester) String() string
- type Header
- type Requester
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetBoolValue ¶
GetBoolValue will attempt to convert the given value to a bool
func GetFloatValue ¶
GetFloatValue will attempt to convert the given value to a float64
func GetIntValue ¶
GetIntValue will attempt to convert the given value to an int64
func GetStringValue ¶
GetStringValue will attempt to convert the given value to a string
func Retries ¶
func Retries(retries int) func(r *HTTPRequester)
Retries sets max number of retries for failed calls
func Timeout ¶
func Timeout(timeout time.Duration) func(r *HTTPRequester)
Timeout sets http client timeout
Types ¶
type CancelableExecutionCtx ¶
type CancelableExecutionCtx struct { Wg *sync.WaitGroup Ctx context.Context CancelFunc context.CancelFunc }
CancelableExecutionCtx has WithCancel implementation
func NewCancelableExecutionCtx ¶
func NewCancelableExecutionCtx() *CancelableExecutionCtx
NewCancelableExecutionCtx returns constructed object
func (CancelableExecutionCtx) GetContext ¶
func (ctx CancelableExecutionCtx) GetContext() context.Context
GetContext is context getter
func (CancelableExecutionCtx) GetWaitSync ¶
func (ctx CancelableExecutionCtx) GetWaitSync() *sync.WaitGroup
GetWaitSync is waitgroup getter
func (CancelableExecutionCtx) TerminateAndWait ¶
func (ctx CancelableExecutionCtx) TerminateAndWait()
TerminateAndWait sends termination signal and waits
type ExecutionCtx ¶
type ExecutionCtx interface { TerminateAndWait() GetContext() context.Context GetWaitSync() *sync.WaitGroup }
ExecutionCtx is the interface, user can overwrite it
type HTTPRequester ¶
type HTTPRequester struct {
// contains filtered or unexported fields
}
HTTPRequester contains main info
func NewHTTPRequester ¶
func NewHTTPRequester(url string, params ...func(*HTTPRequester)) *HTTPRequester
NewHTTPRequester makes Requester with api and parameters. Sets defaults url has a complete url of the request like https://cdn.optimizely.com/datafiles/24234.json
func (HTTPRequester) Do ¶
func (r HTTPRequester) Do(method string, body io.Reader, headers []Header) (response []byte, code int, err error)
Do executes request and returns response body for requested uri (sdkKey.json).
func (HTTPRequester) Get ¶
func (r HTTPRequester) Get(headers ...Header) (response []byte, code int, err error)
Get executes HTTP GET with url and optional extra headers, returns body in []bytes url created as url+sdkKey.json
func (HTTPRequester) GetObj ¶
func (r HTTPRequester) GetObj(result interface{}, headers ...Header) error
GetObj executes HTTP GET with url and optional extra headers, returns filled object
func (HTTPRequester) Post ¶
func (r HTTPRequester) Post(body interface{}, headers ...Header) (response []byte, code int, err error)
Post executes HTTP POST with url, body and optional extra headers
func (HTTPRequester) PostObj ¶
func (r HTTPRequester) PostObj(body, result interface{}, headers ...Header) error
PostObj executes HTTP POST with uri, body and optional extra headers. Returns filled object
func (HTTPRequester) String ¶
func (r HTTPRequester) String() string
type Requester ¶
type Requester interface { Get(...Header) (response []byte, code int, err error) GetObj(result interface{}, headers ...Header) error Post(body interface{}, headers ...Header) (response []byte, code int, err error) PostObj(body interface{}, result interface{}, headers ...Header) error String() string }
Requester is used to make outbound requests with