Documentation ¶
Overview ¶
Package utils //
Package utils //
Package utils //
Index ¶
- Constants
- func Client(client http.Client) func(r *HTTPRequester)
- 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 IsValidAttribute(value interface{}) bool
- func Retries(retries int) func(r *HTTPRequester)
- func Timeout(timeout time.Duration) func(r *HTTPRequester)
- type ExecGroup
- type HTTPRequester
- func (r HTTPRequester) Do(url, method string, body io.Reader, headers []Header) (response []byte, responseHeaders http.Header, code int, err error)
- func (r HTTPRequester) Get(url string, headers ...Header) (response []byte, responseHeaders http.Header, code int, err error)
- func (r HTTPRequester) GetObj(url string, result interface{}, headers ...Header) error
- func (r HTTPRequester) Post(url string, body interface{}, headers ...Header) (response []byte, responseHeaders http.Header, code int, err error)
- func (r HTTPRequester) PostObj(url string, body, result interface{}, headers ...Header) error
- func (r HTTPRequester) String() string
- type Header
- type Requester
Constants ¶
const ( // HeaderContentType is the HTTP Content Type header. HeaderContentType = "Content-Type" // HeaderAuthorization is the HTTP Authorization Type header. HeaderAuthorization = "Authorization" // HeaderAccept is the HTTP Accept Type header. HeaderAccept = "Accept" // ContentTypeJSON is the Content-Type value for a JSON response. ContentTypeJSON = "application/json" )
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 IsValidAttribute ¶
func IsValidAttribute(value interface{}) bool
IsValidAttribute check if attribute value is valid
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 ExecGroup ¶
type ExecGroup struct {
// contains filtered or unexported fields
}
ExecGroup is a utility for managing graceful, blocking cancellation of goroutines.
func NewExecGroup ¶
func NewExecGroup(ctx context.Context, logger logging.OptimizelyLogProducer) *ExecGroup
NewExecGroup returns constructed object
func (ExecGroup) Go ¶
Go initiates a goroutine with the inputted function. Each invocation increments a shared WaitGroup before being initiated. Once the supplied function exits the WaitGroup is decremented. A common ctx is passed to each input function to signal a shutdown sequence.
func (ExecGroup) TerminateAndWait ¶
func (c ExecGroup) TerminateAndWait()
TerminateAndWait sends termination signal and waits
type HTTPRequester ¶
type HTTPRequester struct {
// contains filtered or unexported fields
}
HTTPRequester contains main info
func NewHTTPRequester ¶
func NewHTTPRequester(logger logging.OptimizelyLogProducer, params ...func(*HTTPRequester)) *HTTPRequester
NewHTTPRequester makes Requester with api and parameters. Sets defaults api has the base part of request's url, like http://localhost/api/v1
func (HTTPRequester) Do ¶
func (r HTTPRequester) Do(url, method string, body io.Reader, headers []Header) (response []byte, responseHeaders http.Header, code int, err error)
Do executes request and returns response body for requested url
func (HTTPRequester) Get ¶
func (r HTTPRequester) Get(url string, headers ...Header) (response []byte, responseHeaders http.Header, code int, err error)
Get executes HTTP GET with url and optional extra headers, returns body in []bytes
func (HTTPRequester) GetObj ¶
func (r HTTPRequester) GetObj(url string, 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(url string, body interface{}, headers ...Header) (response []byte, responseHeaders http.Header, code int, err error)
Post executes HTTP POST with url, body and optional extra headers
func (HTTPRequester) PostObj ¶
func (r HTTPRequester) PostObj(url string, body, result interface{}, headers ...Header) error
PostObj executes HTTP POST with url, body and optional extra headers. Returns filled object
func (HTTPRequester) String ¶
func (r HTTPRequester) String() string
type Requester ¶
type Requester interface { Get(url string, headers ...Header) (response []byte, responseHeaders http.Header, code int, err error) GetObj(url string, result interface{}, headers ...Header) error Post(url string, body interface{}, headers ...Header) (response []byte, responseHeaders http.Header, code int, err error) PostObj(url string, body interface{}, result interface{}, headers ...Header) error String() string }
Requester is used to make outbound requests with