Documentation ¶
Overview ¶
Package client is a generated GoMock package.
Index ¶
- type Client
- func (c *Client) Do(ctx context.Context, request *Request) (res *http.Response, err error)
- func (c *Client) GetJSON(ctx context.Context, request *Request, response interface{}) error
- func (c *Client) GetXML(ctx context.Context, request *Request, response interface{}) error
- func (c *Client) NewRequest() *Request
- func (c *Client) Parse(ctx context.Context, request *Request, response interface{}, ...) error
- func (c *Client) ParseJSON(ctx context.Context, request *Request, response interface{}) error
- func (c *Client) ParseXML(ctx context.Context, request *Request, response interface{}) error
- func (c *Client) PostJSON(ctx context.Context, request *Request, response interface{}) error
- func (c *Client) PutJSON(ctx context.Context, request *Request, response interface{}) error
- type DeadLetter
- type Letter
- type MockDeadLetter
- type MockDeadLetterMockRecorder
- type Option
- type Request
- func (r *Request) AddHeader(key string, value ...string) *Request
- func (r *Request) AddQuery(key string, value ...string) *Request
- func (r *Request) Body(body []byte) *Request
- func (r *Request) Host(host string) *Request
- func (r *Request) Method(method string) *Request
- func (r *Request) Path(path string, opts ...interface{}) *Request
- func (r *Request) SetBasicAuth(username, password string) *Request
- func (r *Request) SetHeader(key string, value ...string) *Request
- func (r *Request) SetQuery(key string, value ...string) *Request
- func (r *Request) URL() (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a wrapper for http.Client Has easy to use methods to send http requests Provides a deadletter to save requests that could not be sent and a rate limiter to limit the number of requests per second
func New ¶
New create a client with multiple options or get the default client without providing any options
func (*Client) GetJSON ¶
GetJSON execute a get method with the given request and then unmarshal the json response body
func (*Client) GetXML ¶
GetXML execute a get method with the given request and then unmarshal the xml response body
func (*Client) NewRequest ¶
NewRequest creates a new request with the given context
func (*Client) Parse ¶
func (c *Client) Parse(ctx context.Context, request *Request, response interface{}, parser func(bodyBytes []byte, response interface{}) error) error
Parse send a request with the given request properties Read the body with the given parser function
func (*Client) ParseJSON ¶
ParseJSON send a request with given request properties Read the body and run json unmarshaler to fill the given response
func (*Client) ParseXML ¶
ParseXML send a request with the given request properties Read the body and run xml unmarshaler to fill the given response
type DeadLetter ¶
DeadLetter save request to somewhere to ensure consistency
type Letter ¶
type Letter struct { Method string `json:"method"` URL string `json:"url"` Body []byte `json:"body"` Headers map[string][]string `json:"headers"` }
Letter is a letter that is sent to deadletter
type MockDeadLetter ¶
type MockDeadLetter struct {
// contains filtered or unexported fields
}
MockDeadLetter is a mock of DeadLetter interface.
func NewMockDeadLetter ¶
func NewMockDeadLetter(ctrl *gomock.Controller) *MockDeadLetter
NewMockDeadLetter creates a new mock instance.
func (*MockDeadLetter) EXPECT ¶
func (m *MockDeadLetter) EXPECT() *MockDeadLetterMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockDeadLetter) Save ¶
func (m *MockDeadLetter) Save(letter *Letter) error
Save mocks base method.
type MockDeadLetterMockRecorder ¶
type MockDeadLetterMockRecorder struct {
// contains filtered or unexported fields
}
MockDeadLetterMockRecorder is the mock recorder for MockDeadLetter.
func (*MockDeadLetterMockRecorder) Save ¶
func (mr *MockDeadLetterMockRecorder) Save(letter interface{}) *gomock.Call
Save indicates an expected call of Save.
type Option ¶
type Option func(c *Client)
Option is a function that configures a client
func WithDeadLetter ¶
func WithDeadLetter(deadLetter DeadLetter) Option
WithDeadLetter create client option function with deadletter properties
func WithHTTPClient ¶
WithHTTPClient create client option function with http client
func WithRateLimit ¶
WithRateLimit create client option function with http client
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request use this request struct to send http requests
func (*Request) AddHeader ¶
AddHeader if given header key currently has a value it will add another one if the key does not exists it will add a new key value
func (*Request) AddQuery ¶
AddQuery if given query key currently has a value it will add another one if the key does not exists it will add a new key value
func (*Request) Path ¶
Path sets the given request path to request. To avoid fmt.Sprintf call while calling the function you can directly give the formatted string as path variable and options after that function will automatically insert the paremeters
func (*Request) SetBasicAuth ¶
SetBasicAuth sets the basic auth header
func (*Request) SetHeader ¶
SetHeader if given header key currently has a value it will replace it with the given value if the key does not exists it will add a new key value