jsonclient

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BodyClose added in v0.9.1

func BodyClose(r io.ReadCloser)

https://github.com/golang/go/issues/60240

func ReadJsonPayload added in v0.9.0

func ReadJsonPayload(h http.Header, r io.Reader, out any) error

func WriteJsonPayload added in v0.9.0

func WriteJsonPayload(h http.Header, w io.Writer, in any) error

Types

type Client

type Client struct {
	// The endpoint of the server conforming to this interface, with scheme,
	// https://api.deepmap.com for example. This can contain a path relative to
	// the server, such as https://api.deepmap.com/dev-test, and all the paths in
	// the swagger spec will be appended to the server.
	Server string

	// Doer for performing requests, typically a *http.Client with any customized
	// settings, such as certificate chains.
	Client HttpRequestDoer

	// A list of callbacks for modifying requests which are generated before
	// sending over the network.
	RequestEditors []RequestEditorFn
}

Client which conforms to the OpenAPI3 specification for this service.

func New

func New(server string, opts ...ClientOption) (*Client, error)

Creates a new Client, with reasonable defaults

func NewUnix

func NewUnix(sockPath string) (*Client, error)

func (*Client) Do

func (self *Client) Do(req *http.Request, out any) error

func (*Client) Get

func (self *Client) Get(ctx context.Context, endpoint string, out any,
	reqEditors ...RequestEditorFn,
) error

func (*Client) NewRequest

func (self *Client) NewRequest(ctx context.Context, method, endpoint string,
	body io.Reader, reqEditors ...RequestEditorFn,
) (*http.Request, error)

func (*Client) Post

func (self *Client) Post(ctx context.Context, endpoint string, in, out any,
	reqEditors ...RequestEditorFn,
) error

func (*Client) PostResponseStream added in v0.9.0

func (self *Client) PostResponseStream(ctx context.Context, endpoint string,
	in, out any, reqEditors ...RequestEditorFn,
) (io.ReadCloser, error)

func (*Client) PostStream added in v0.9.0

func (self *Client) PostStream(ctx context.Context, endpoint string,
	in, out any, r io.Reader, reqEditors ...RequestEditorFn,
) error

func (*Client) WithRequestEditorFn

func (self *Client) WithRequestEditorFn(fn RequestEditorFn) *Client

WithRequestEditorFn allows setting up a callback function, which will be called right before sending the request. This can be used to mutate the request.

type ClientOption

type ClientOption func(*Client) error

ClientOption allows setting custom parameters during construction

func WithControlPath

func WithControlPath(sockPath string) ClientOption

func WithHTTPClient

func WithHTTPClient(doer HttpRequestDoer) ClientOption

WithHTTPClient allows overriding the default Doer, which is automatically created using http.Client. This is useful for tests.

func WithRequestEditorFn added in v0.9.0

func WithRequestEditorFn(fn RequestEditorFn) ClientOption

type HttpRequestDoer

type HttpRequestDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

Doer performs HTTP requests.

The standard http.Client implements this interface.

type RequestEditorFn

type RequestEditorFn func(ctx context.Context, req *http.Request) error

RequestEditorFn is the function signature for the RequestEditor callback function.

Jump to

Keyboard shortcuts

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