Documentation ¶
Index ¶
- func EncodeURL(urlFormat string, args ...interface{}) string
- func ExtractExtraProperties(bytes []byte, value interface{}, exclude ...string) (map[string]interface{}, error)
- func MarshalJSONWithExtraProperties(marshaler interface{}, extraProperties map[string]interface{}) ([]byte, error)
- func MarshalJSONWithExtraProperty(marshaler interface{}, key string, value interface{}) ([]byte, error)
- func MergeHeaders(left, right http.Header) http.Header
- func QueryValues(v interface{}) (url.Values, error)
- func StringifyJSON(value interface{}) (string, error)
- func WriteMultipartJSON(writer *multipart.Writer, field string, value interface{}) error
- type APIError
- type BaseURLOption
- type BodyPropertiesOption
- type CallParams
- type Caller
- type CallerParams
- type Date
- type DateTime
- type ErrorDecoder
- type HTTPClient
- type HTTPClientOption
- type HTTPHeaderOption
- type MaxAttemptsOption
- type QueryEncoder
- type QueryParametersOption
- type RequestOption
- type RequestOptions
- type Retrier
- type RetryFunc
- type RetryOption
- type TokenOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodeURL ¶ added in v0.0.14
EncodeURL encodes the given arguments into the URL, escaping values as needed.
func ExtractExtraProperties ¶ added in v0.0.14
func ExtractExtraProperties(bytes []byte, value interface{}, exclude ...string) (map[string]interface{}, error)
ExtractExtraProperties extracts any extra properties from the given value.
func MarshalJSONWithExtraProperties ¶ added in v0.0.14
func MarshalJSONWithExtraProperties(marshaler interface{}, extraProperties map[string]interface{}) ([]byte, error)
MarshalJSONWithExtraProperties marshals the given value to JSON, including any extra properties.
func MarshalJSONWithExtraProperty ¶ added in v0.0.14
func MarshalJSONWithExtraProperty(marshaler interface{}, key string, value interface{}) ([]byte, error)
MarshalJSONWithExtraProperty marshals the given value to JSON, including the extra property.
func MergeHeaders ¶ added in v0.0.8
MergeHeaders merges the given headers together, where the right takes precedence over the left.
func QueryValues ¶ added in v0.0.8
QueryValues encodes url.Values from request objects.
Note: This type is inspired by Google's query encoding library, but supports far less customization and is tailored to fit this SDK's use case.
func StringifyJSON ¶
StringifyJSON returns a pretty JSON string representation of the given value.
Types ¶
type APIError ¶
type APIError struct { StatusCode int `json:"-"` // contains filtered or unexported fields }
APIError is a lightweight wrapper around the standard error interface that preserves the status code from the RPC, if any.
func NewAPIError ¶
NewAPIError constructs a new API error.
type BaseURLOption ¶ added in v0.0.8
type BaseURLOption struct {
BaseURL string
}
BaseURLOption implements the RequestOption interface.
type BodyPropertiesOption ¶ added in v0.0.17
type BodyPropertiesOption struct {
BodyProperties map[string]interface{}
}
BodyPropertiesOption implements the RequestOption interface.
type CallParams ¶
type CallParams struct { URL string Method string MaxAttempts uint Headers http.Header BodyProperties map[string]interface{} QueryParameters url.Values Client HTTPClient Request interface{} Response interface{} ResponseIsOptional bool ErrorDecoder ErrorDecoder }
CallParams represents the parameters used to issue an API call.
type Caller ¶
type Caller struct {
// contains filtered or unexported fields
}
Caller calls APIs and deserializes their response, if any.
func NewCaller ¶
func NewCaller(params *CallerParams) *Caller
NewCaller returns a new *Caller backed by the given parameters.
type CallerParams ¶ added in v0.0.8
type CallerParams struct { Client HTTPClient MaxAttempts uint }
CallerParams represents the parameters used to constrcut a new *Caller.
type Date ¶ added in v0.0.8
type Date struct {
// contains filtered or unexported fields
}
DateTime wraps time.Time and adapts its JSON representation to conform to a RFC3339 date (e.g. 2006-01-02).
Ref: https://ijmacd.github.io/rfc3339-iso8601
func NewDate ¶ added in v0.0.8
NewDate returns a new *Date. If the given time.Time is nil, nil will be returned.
func NewOptionalDate ¶ added in v0.0.8
NewOptionalDate returns a new *Date. If the given time.Time is nil, nil will be returned.
func (*Date) MarshalJSON ¶ added in v0.0.8
func (*Date) Time ¶ added in v0.0.8
Time returns the Date's underlying time, if any. If the date is nil, the zero value is returned.
func (*Date) TimePtr ¶ added in v0.0.8
TimePtr returns a pointer to the Date's underlying time.Time, if any.
func (*Date) UnmarshalJSON ¶ added in v0.0.8
type DateTime ¶ added in v0.0.8
type DateTime struct {
// contains filtered or unexported fields
}
DateTime wraps time.Time and adapts its JSON representation to conform to a RFC3339 date-time (e.g. 2017-07-21T17:32:28Z).
Ref: https://ijmacd.github.io/rfc3339-iso8601
func NewDateTime ¶ added in v0.0.8
NewDateTime returns a new *DateTime.
func NewOptionalDateTime ¶ added in v0.0.8
NewOptionalDateTime returns a new *DateTime. If the given time.Time is nil, nil will be returned.
func (*DateTime) MarshalJSON ¶ added in v0.0.8
func (*DateTime) Time ¶ added in v0.0.8
Time returns the DateTime's underlying time, if any. If the date-time is nil, the zero value is returned.
func (*DateTime) TimePtr ¶ added in v0.0.8
TimePtr returns a pointer to the DateTime's underlying time.Time, if any.
func (*DateTime) UnmarshalJSON ¶ added in v0.0.8
type ErrorDecoder ¶
ErrorDecoder decodes *http.Response errors and returns a typed API error (e.g. *APIError).
type HTTPClient ¶
HTTPClient is an interface for a subset of the *http.Client.
type HTTPClientOption ¶ added in v0.0.8
type HTTPClientOption struct {
HTTPClient HTTPClient
}
HTTPClientOption implements the RequestOption interface.
type HTTPHeaderOption ¶ added in v0.0.8
HTTPHeaderOption implements the RequestOption interface.
type MaxAttemptsOption ¶ added in v0.0.8
type MaxAttemptsOption struct {
MaxAttempts uint
}
MaxAttemptsOption implements the RequestOption interface.
type QueryEncoder ¶ added in v0.0.8
QueryEncoder is an interface implemented by any type that wishes to encode itself into URL values in a non-standard way.
type QueryParametersOption ¶ added in v0.0.17
QueryParametersOption implements the RequestOption interface.
type RequestOption ¶ added in v0.0.8
type RequestOption interface {
// contains filtered or unexported methods
}
RequestOption adapts the behavior of the client or an individual request.
type RequestOptions ¶ added in v0.0.8
type RequestOptions struct { BaseURL string HTTPClient HTTPClient HTTPHeader http.Header BodyProperties map[string]interface{} QueryParameters url.Values MaxAttempts uint Token string }
RequestOptions defines all of the possible request options.
This type is primarily used by the generated code and is not meant to be used directly; use the option package instead.
func NewRequestOptions ¶ added in v0.0.8
func NewRequestOptions(opts ...RequestOption) *RequestOptions
NewRequestOptions returns a new *RequestOptions value.
This function is primarily used by the generated code and is not meant to be used directly; use RequestOption instead.
func (*RequestOptions) ToHeader ¶ added in v0.0.8
func (r *RequestOptions) ToHeader() http.Header
ToHeader maps the configured request options into a http.Header used for the request(s).
type Retrier ¶ added in v0.0.8
type Retrier struct {
// contains filtered or unexported fields
}
Retrier retries failed requests a configurable number of times with an exponential back-off between each retry.
func NewRetrier ¶ added in v0.0.8
func NewRetrier(opts ...RetryOption) *Retrier
NewRetrier constructs a new *Retrier with the given options, if any.
func (*Retrier) Run ¶ added in v0.0.8
func (r *Retrier) Run( fn RetryFunc, request *http.Request, errorDecoder ErrorDecoder, opts ...RetryOption, ) (*http.Response, error)
Run issues the request and, upon failure, retries the request if possible.
The request will be retried as long as the request is deemed retriable and the number of retry attempts has not grown larger than the configured retry limit.
type RetryFunc ¶ added in v0.0.8
RetryFunc is a retriable HTTP function call (i.e. *http.Client.Do).
type RetryOption ¶ added in v0.0.8
type RetryOption func(*retryOptions)
RetryOption adapts the behavior the *Retrier.
func WithMaxAttempts ¶ added in v0.0.8
func WithMaxAttempts(attempts uint) RetryOption
WithMaxAttempts configures the maximum number of attempts of the *Retrier.
type TokenOption ¶ added in v0.0.8
type TokenOption struct {
Token string
}
TokenOption implements the RequestOption interface.