Documentation ¶
Overview ¶
Package backend provides a generic interface to make calls to the Aurora backend. It implements it in the `AuroraBackend` struct, which actually is configured to make API calls, but others can be implemented to behave differently or hit a different endpoint. This is particularly useful during testing.
Index ¶
- type AuroraBackend
- func (b *AuroraBackend) Call(params *CallParams) (*http.Response, error)
- func (b *AuroraBackend) Do(req *http.Request) (*http.Response, error)
- func (b *AuroraBackend) NewRequest(params *CallParams) (*http.Request, error)
- func (b *AuroraBackend) SetBaseURL(url string)
- func (b *AuroraBackend) SetClient(client *http.Client)
- type Backend
- type CallParams
- type Credentials
- type MultipartFile
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuroraBackend ¶
type AuroraBackend struct { BaseURL string // contains filtered or unexported fields }
AuroraBackend is an implementation that actually executes requests with the API server.
func (*AuroraBackend) Call ¶
func (b *AuroraBackend) Call(params *CallParams) (*http.Response, error)
Call implements a call to the backend.
func (*AuroraBackend) NewRequest ¶
func (b *AuroraBackend) NewRequest(params *CallParams) (*http.Request, error)
NewRequest creates an http.Request from the given parameters.
func (*AuroraBackend) SetBaseURL ¶
func (b *AuroraBackend) SetBaseURL(url string)
SetBaseURL sets the base URL for the backend. This is useful if you want to change the backend endpoint to a local or test deployment.
func (*AuroraBackend) SetClient ¶
func (b *AuroraBackend) SetClient(client *http.Client)
SetClient sets the http client for the backend.
type Backend ¶
type Backend interface { // Set some properties of the backend SetBaseURL(url string) SetClient(client *http.Client) // Call the backend to perform a request Call(params *CallParams) (*http.Response, error) // Lower level methods that can be called as well NewRequest(params *CallParams) (*http.Request, error) Do(req *http.Request) (*http.Response, error) }
Backend is an interface for a general backend that executes a given request.
func NewAuroraBackend ¶
func NewAuroraBackend() Backend
NewAuroraBackend returns an AuroraBackend with default configuration.
type CallParams ¶
type CallParams struct { // Method is one of GET, POST, PATCH, DELETE, etc. Method string // Path is the relative path of the query Path string // Headers are any additional headers to send in the request Headers http.Header // Body is any data to send in the body Body io.Reader // Form is ignored for non-multipart calls. It is multipart form data Form url.Values // Query is querystring parameters Query url.Values // Files is ignored for non-multipart calls. It is multipart file data Files []MultipartFile // Credentials are the AppID, AppToken, etc. required to make the call Credentials *Credentials }
CallParams describe the request to send.
type Credentials ¶
type Credentials struct { // AppID is the appliacation ID (sent for 'X-Application-ID' header) AppID string // AppToken is the application token (sent for 'X-Application-Token' header) AppToken string // DeviceID is the device ID (sent for 'X-Device-ID' header) DeviceID string }
Credentials for the API request.
type MultipartFile ¶
type MultipartFile struct { // Name is the form field name Name string // Filename is the file name to upload the file as FileName string // Data is the file data Data []byte }
MultipartFile is an in-memory representation of a file to upload.