Documentation
¶
Index ¶
- type HTTPClient
- type HTTPClientInterface
- type JSONClient
- func (c JSONClient) DELETE(path string, successReceiver, errorReceiver interface{}) (*http.Response, error)
- func (c JSONClient) GET(path string, successReceiver, errorReceiver interface{}) (*http.Response, error)
- func (c JSONClient) NewMultipartWriter() *MultipartWriter
- func (c JSONClient) POST(path string, body, successReceiver, errorReceiver interface{}) (*http.Response, error)
- func (c JSONClient) PUT(path string, body, successReceiver, errorReceiver interface{}) (*http.Response, error)
- func (c JSONClient) WithAuthorization(auth string) RESTClient
- type JSONClientConfig
- type MockHTTPClient
- type MockRESTClient
- func (m MockRESTClient) DELETE(path string, successReceiver, errorReceiver interface{}) (bool, error)
- func (m MockRESTClient) GET(path string, successReceiver, errorReceiver interface{}) (bool, error)
- func (m MockRESTClient) NewMultipartWriter() *MultipartWriter
- func (m MockRESTClient) POST(path string, body, successReceiver, errorReceiver interface{}) (bool, error)
- func (m MockRESTClient) PUT(path string, body, successReceiver, errorReceiver interface{}) (bool, error)
- func (m MockRESTClient) WithAuthorization(auth string) RESTClient
- type MultipartWriter
- func (mw *MultipartWriter) AddField(name string, body interface{}) error
- func (mw *MultipartWriter) AddFile(name, fileName string, fileContents io.Reader) error
- func (mw *MultipartWriter) POST(path string, successReceiver, errorReceiver interface{}) (*http.Response, error)
- func (mw *MultipartWriter) PUT(path string, successReceiver, errorReceiver interface{}) (*http.Response, error)
- type MultipartWriterConfig
- type RESTClient
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HTTPClient ¶
HTTPClient implements methods as a wrapper over the Go HttpClient
func (*HTTPClient) SetTransport ¶
func (h *HTTPClient) SetTransport(transport *http.Transport)
SetTransport sets the transport information for this HTTP client
type HTTPClientInterface ¶
HTTPClientInterface is an interface over the Go HttpClient
type JSONClient ¶
type JSONClient struct {
// contains filtered or unexported fields
}
JSONClient provides a set of methods for working with RESTful endpoints that accept and return JSON data
func NewJSONClient ¶
func NewJSONClient(config JSONClientConfig) JSONClient
NewJSONClient creates a new JSON-based REST client
func (JSONClient) DELETE ¶
func (c JSONClient) DELETE(path string, successReceiver, errorReceiver interface{}) (*http.Response, error)
DELETE performs an HTTP DELETE operation. You provide a path, which should exclude the TLD, as this is defined in BaseURL. If your request requires authorization call WithAuthorization first, then DELETE.
If some type of error occurs when creating the request, executing the request, or unmarshalling the response, err will be populated. The http.Response is returned so callers can inspect the status.
func (JSONClient) GET ¶
func (c JSONClient) GET(path string, successReceiver, errorReceiver interface{}) (*http.Response, error)
GET performs an HTTP GET operation. You provide a path, which should exclude the the TLD, as this is defined in BaseURL. If your request requires authorization call WithAuthorization first, then GET.
If some type of error occurs when creating the request, executing the request, or unmarshalling the response, err will be populated. The http.Response is returned so callers can inspect the status.
func (JSONClient) NewMultipartWriter ¶ added in v6.1.0
func (c JSONClient) NewMultipartWriter() *MultipartWriter
NewMultipartWriter returns a MultipartWriter. This is used to POST and PUT multipart forms. Use this when you need to POST or PUT files, for example.
func (JSONClient) POST ¶
func (c JSONClient) POST(path string, body, successReceiver, errorReceiver interface{}) (*http.Response, error)
POST performs an HTTP POST operation. You provide a path, which should exclude the TLD, as this is defined in BaseURL. If your request requires authorization call WithAuthorization first, then POST.
If some type of error occurs when creating the request, executing the request, or unmarshalling the response, err will be populated. The http.Response is returned so callers can inspect the status.
func (JSONClient) PUT ¶
func (c JSONClient) PUT(path string, body, successReceiver, errorReceiver interface{}) (*http.Response, error)
PUT performs an HTTP PUT operation. You provide a path, which should exclude the the TLD, as this is defined in BaseURL. If your request requires authorization call WithAuthorization first, then PUT.
If some type of error occurs when creating the request, executing the request, or unmarshalling the response, err will be populated. The http.Response is returned so callers can inspect the status.
func (JSONClient) WithAuthorization ¶
func (c JSONClient) WithAuthorization(auth string) RESTClient
WithAuthorization returns an instance of RESTClient with an authorization header set
type JSONClientConfig ¶ added in v6.3.0
type JSONClientConfig struct { BaseURL string DebugMode bool HTTPClient HTTPClientInterface Logger *logrus.Entry CustomHeaders map[string]string OmitContentType bool }
JSONClientConfig is used to configure a JSONClient struct
type MockHTTPClient ¶
type MockHTTPClient struct { DoFunc func(req *http.Request) (*http.Response, error) SetTransportFunc func(transport *http.Transport) }
MockHTTPClient is a mock HTTP client
func (*MockHTTPClient) SetTransport ¶
func (m *MockHTTPClient) SetTransport(transport *http.Transport)
SetTransport mocks the SetTransport method
type MockRESTClient ¶
type MockRESTClient struct { DELETEFunc func(path string, successReceiver, errorReceiver interface{}) (bool, error) GETFunc func(path string, successReceiver, errorReceiver interface{}) (bool, error) NewMultipartWriterFunc func() *MultipartWriter POSTFunc func(path string, body, successReceiver, errorReceiver interface{}) (bool, error) PUTFunc func(path string, body, successReceiver, errorReceiver interface{}) (bool, error) WithAuthorizationFunc func(auth string) RESTClient }
MockRESTClient is a mock for RESTClient
func (MockRESTClient) DELETE ¶
func (m MockRESTClient) DELETE(path string, successReceiver, errorReceiver interface{}) (bool, error)
DELETE is a mock method
func (MockRESTClient) GET ¶
func (m MockRESTClient) GET(path string, successReceiver, errorReceiver interface{}) (bool, error)
GET is a mock method
func (MockRESTClient) NewMultipartWriter ¶ added in v6.1.0
func (m MockRESTClient) NewMultipartWriter() *MultipartWriter
NewMultipartWriter is a mock method
func (MockRESTClient) POST ¶
func (m MockRESTClient) POST(path string, body, successReceiver, errorReceiver interface{}) (bool, error)
POST is a mock method
func (MockRESTClient) PUT ¶
func (m MockRESTClient) PUT(path string, body, successReceiver, errorReceiver interface{}) (bool, error)
PUT is a mock method
func (MockRESTClient) WithAuthorization ¶
func (m MockRESTClient) WithAuthorization(auth string) RESTClient
WithAuthorization is a mock method
type MultipartWriter ¶ added in v6.1.0
type MultipartWriter struct {
// contains filtered or unexported fields
}
func NewMultipartWriter ¶ added in v6.1.0
func NewMultipartWriter(config MultipartWriterConfig) *MultipartWriter
NewMultipartWriter creates a new MultipartWriter
func (*MultipartWriter) AddField ¶ added in v6.1.0
func (mw *MultipartWriter) AddField(name string, body interface{}) error
AddField adds a field to this multipart form. It accepts two types: string, json.Marshaler. For the latter, this would be any struct or type that implements the json.Marshaler interface.
func (*MultipartWriter) AddFile ¶ added in v6.1.0
func (mw *MultipartWriter) AddFile(name, fileName string, fileContents io.Reader) error
AddFile adds a file to this multipart form.
func (*MultipartWriter) POST ¶ added in v6.1.0
func (mw *MultipartWriter) POST(path string, successReceiver, errorReceiver interface{}) (*http.Response, error)
POST sends a multipart form via POST. The fields being sent should be added prior to calling POST by using the AddField and AddFile methods.
type MultipartWriterConfig ¶ added in v6.3.0
type RESTClient ¶
type RESTClient interface { DELETE(path string, successReceiver, errorReceiver interface{}) (*http.Response, error) GET(path string, successReceiver, errorReceiver interface{}) (*http.Response, error) NewMultipartWriter() *MultipartWriter POST(path string, body, successReceiver, errorReceiver interface{}) (*http.Response, error) PUT(path string, body, successReceiver, errorReceiver interface{}) (*http.Response, error) WithAuthorization(auth string) RESTClient }
RESTClient defines an interface for working with RESTful endpoints