Documentation
¶
Index ¶
- func NewRequest(options ...RequestOption) *request
- type ApiClientCallable
- type OpenApiClient
- type RequestOption
- func Body(body any) RequestOption
- func Data(key string, value any) RequestOption
- func Header(key string, value string) RequestOption
- func Headers(headers map[string][]string) RequestOption
- func Param(key string, value any) RequestOption
- func Params(params map[string][]any) RequestOption
- func RequestJSON(fn ApiClientCallable) RequestOption
- func RequestOptions(options ...RequestOption) RequestOption
- func Result(result any) RequestOption
- func WithClient(client OpenApiClient) RequestOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewRequest ¶
func NewRequest(options ...RequestOption) *request
NewRequest creates a new request, and optionally applies options.
Types ¶
type ApiClientCallable ¶
type OpenApiClient ¶
type RequestOption ¶
type RequestOption func(*request)
RequestOption is a function that modifies a request.
func Body ¶
func Body(body any) RequestOption
Body sets the body of the request. This can take any JSON serializable value.
func Data ¶
func Data(key string, value any) RequestOption
Data adds data to the request body payload. If the body has not been set it will be initialized to a map. If the body has been set and is not a map, this will panic. If the body is a map, the data will be added to it as a top level key.
func Header ¶
func Header(key string, value string) RequestOption
Header adds a header to the request.
Parameters:
- key: The header key
- value: The header value
Example:
Header("Content-Type", "application/json")
func Headers ¶
func Headers(headers map[string][]string) RequestOption
Headers adds multiple headers to the request from a map.
Parameters:
- headers: A map of header keys to a list of values
Example:
headers := map[string][]string{
"Content-Type": {"application/json"},
"Authorization": {"Bearer <token>"},
}
func Param ¶
func Param(key string, value any) RequestOption
Param adds a parameter to the request. This can be used as a path parameter or a query parameter. The parameter key name and value type must match what is specified in the OpenApiSpec for the endpoint you are calling.
func Params ¶
func Params(params map[string][]any) RequestOption
Params adds multiple parameters to the request from a map.
func RequestJSON ¶
func RequestJSON(fn ApiClientCallable) RequestOption
RequestJSON specifies a function that will be used to make the request.
func RequestOptions ¶
func RequestOptions(options ...RequestOption) RequestOption
RequestOptions creates a function that applies a list of options to a request. This allows an option set to be reused over multiple requests.
func Result ¶
func Result(result any) RequestOption
Result sets a pointer to a struct to use for unmarshalling the response body payload. This can be any JSON serializable value.
func WithClient ¶
func WithClient(client OpenApiClient) RequestOption
WithClient sets the API client to use for the request.