rest

package
v0.0.0-...-ddf4d86 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. API error responses are expected to have either no response body, or a XML response body that maps to ErrorResponse. Any other response body will be silently ignored.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(http *http.Client) *Client

func (*Client) Do

func (c *Client) Do(req *http.Request, responseBody interface{}) (*http.Response, error)

Do sends an API request and returns the API response. The API response is XML decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response will be written to v, without attempting to decode it.

func (*Client) GetEndpoint

func (c *Client) GetEndpoint(path string) *url.URL

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method, path string, body interface{}) (*http.Request, error)

func (*Client) SetBaseURL

func (c *Client) SetBaseURL(baseURL *url.URL)

func (*Client) SetDebug

func (c *Client) SetDebug(debug bool)

func (*Client) SetDisallowUnknownFields

func (c *Client) SetDisallowUnknownFields(disallowUnknownFields bool)

func (*Client) SetDivisionID

func (c *Client) SetDivisionID(divisionID int)

func (*Client) SetUserAgent

func (c *Client) SetUserAgent(userAgent string)

func (*Client) SubPath

func (c *Client) SubPath(path string) string

func (*Client) SubPathWithID

func (c *Client) SubPathWithID(path string, id string) string

type ErrorMessage

type ErrorMessage struct {
	Lang  string `json:"lang"`
	Value string `json:"value"`
}

type ErrorResponse

type ErrorResponse struct {
	// HTTP response that caused this error
	Response *http.Response

	// HTTP status code
	Code string

	// Fault message
	Message ErrorMessage `json:"message"`
}

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type RequestCompletionCallback

type RequestCompletionCallback func(*http.Request, *http.Response)

RequestCompletionCallback defines the type of the request callback function

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL