Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewByteBody ¶
func NewByteBody(b []byte) io.ReadCloser
NewByteBody creates an io.ReadCloser from a slice of bytes.
func NewMock ¶
func NewMock(r ...MockResponse) *http.Client
NewMock returns a pointer to http.Client with the mocked Transport.
func NewStringBody ¶
func NewStringBody(b string) io.ReadCloser
NewStringBody creates an io.ReadCloser from a string.
func NewStructBody ¶
func NewStructBody(i interface{}) io.ReadCloser
NewStructBody creates an io.ReadCloser from a structure that is attempted to be encoded into JSON. In case of failure, it panics.
Types ¶
type Config ¶
type Config struct { HostPort *hostPort User string Pass string Timeout time.Duration // contains filtered or unexported fields }
Config contains the config http.Client that will be used for the http.Client
func NewClientConfig ¶
func NewClientConfig(host string, port int, user string, pass string, timeout int, insecure bool) (*Config, error)
NewClientConfig handles the parameters that will be used in the HTTP Client If a socket is passed as a URL (http://<host>:<port>), the complex URL will prevail from the passed port
func (*Config) HTTPAdress ¶
HTTPAdress returns the host and port combination so it can be used by the Client http://host:port
type HTTP ¶
type HTTP struct { Config *Config // contains filtered or unexported fields }
HTTP Wraps an http.Client with its config
func (*HTTP) HandleCall ¶
HandleCall is responsible to perform HTTP requests against the secified url it relies on the underlying net/http.Client or Injected CallerInterface.
Because we have to inject the `Content-Type: application/json`, client.Do is used.
type MockResponse ¶
MockResponse Wraps the response of the RoundTrip.
type RoundTripper ¶
type RoundTripper struct { Responses []MockResponse // contains filtered or unexported fields }
RoundTripper is aimed to be used as the Transport property in an http.Client in order to mock the responses that it would return in the normal execution. If the number of responses that are mocked are not enough, an error with the request iteration ID, method and full URL is returned.
func (*RoundTripper) Add ¶
func (rt *RoundTripper) Add(res ...MockResponse) *RoundTripper
Add accepts multiple Response structures as variadric arguments and appends those to the current list of Responses.
func (*RoundTripper) RoundTrip ¶
RoundTrip executes a single HTTP transaction, returning a Response for the provided Request.
RoundTrip should not attempt to interpret the response. In particular, RoundTrip must return err == nil if it obtained a response, regardless of the response's HTTP status code. A non-nil err should be reserved for failure to obtain a response. Similarly, RoundTrip should not attempt to handle higher-level protocol details such as redirects, authentication, or cookies.
RoundTrip should not modify the request, except for consuming and closing the Request's Body. RoundTrip may read fields of the request in a separate goroutine. Callers should not mutate or reuse the request until the Response's Body has been closed.
RoundTrip must always close the body, including on errors, but depending on the implementation may do so in a separate goroutine even after RoundTrip returns. This means that callers wanting to reuse the body for subsequent requests must arrange to wait for the Close call before doing so.
The Request's URL and Header fields must be initialized.