request

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

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 ApiClientCallable func(method string, uri string, body io.Reader, result any, headers map[string][]string) (*http.Response, error)

type OpenApiClient

type OpenApiClient interface {
	RequestJSON(method string, uri string, body io.Reader, result any, headers map[string][]string) (*http.Response, error)
}

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(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.

Jump to

Keyboard shortcuts

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