Documentation
¶
Index ¶
- type Client
- func (c *Client) Delete(ctx context.Context, endpoint string, body any, marshaler Marshaler, ...) (res *http.Response, err error)
- func (c *Client) Do(ctx context.Context, method string, endpoint string, body any, ...) (res *http.Response, err error)
- func (c *Client) Get(ctx context.Context, endpoint string, body any, marshaler Marshaler, ...) (res *http.Response, err error)
- func (c *Client) NewRequest(method string, endpoint string) *RequestBuilder
- func (c *Client) Patch(ctx context.Context, endpoint string, body any, marshaler Marshaler, ...) (res *http.Response, err error)
- func (c *Client) Post(ctx context.Context, endpoint string, body any, marshaler Marshaler, ...) (res *http.Response, err error)
- func (c *Client) Put(ctx context.Context, endpoint string, body any, marshaler Marshaler, ...) (res *http.Response, err error)
- func (c *Client) Use(statge MiddlewareStage, middlewares ...func(context.Context, *Request)) error
- type Configuration
- type HttpClient
- type Marshaler
- type MemPool
- type MemoryPool
- type MiddlewareStage
- type Option
- type Request
- type RequestBuilder
- func (rb *RequestBuilder) Run(ctx context.Context) (res *http.Response, err error)
- func (rb *RequestBuilder) WithBody(body any, marshaler Marshaler) *RequestBuilder
- func (rb *RequestBuilder) WithHeader(key string, val string) *RequestBuilder
- func (rb *RequestBuilder) WithHeaders(headers map[string]string) *RequestBuilder
- func (rb *RequestBuilder) WithPathParameters(pathParams ...string) *RequestBuilder
- func (rb *RequestBuilder) WithQueryParameter(key string, val []string) *RequestBuilder
- func (rb *RequestBuilder) WithQueryParameters(queryParams map[string][]string) *RequestBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps an http.Client with additional functionality.
func (*Client) Delete ¶
func (c *Client) Delete( ctx context.Context, endpoint string, body any, marshaler Marshaler, headers map[string]string, queryParam map[string][]string, pathParams ...string, ) (res *http.Response, err error)
Delete runs an http DELETE request with all the given parameters.
func (*Client) Do ¶
func (c *Client) Do( ctx context.Context, method string, endpoint string, body any, marshaler Marshaler, headers map[string]string, queryParam map[string][]string, pathParams ...string, ) (res *http.Response, err error)
Do runs an http request with all the given parameters.
func (*Client) Get ¶
func (c *Client) Get( ctx context.Context, endpoint string, body any, marshaler Marshaler, headers map[string]string, queryParam map[string][]string, pathParams ...string, ) (res *http.Response, err error)
Get runs an http GET request with all the given parameters.
func (*Client) NewRequest ¶ added in v0.2.0
func (c *Client) NewRequest( method string, endpoint string, ) *RequestBuilder
NewRequest creates a request builder.
func (*Client) Patch ¶
func (c *Client) Patch( ctx context.Context, endpoint string, body any, marshaler Marshaler, headers map[string]string, queryParam map[string][]string, pathParams ...string, ) (res *http.Response, err error)
Patch runs an http PATCH request with all the given parameters.
func (*Client) Post ¶
func (c *Client) Post( ctx context.Context, endpoint string, body any, marshaler Marshaler, headers map[string]string, queryParam map[string][]string, pathParams ...string, ) (res *http.Response, err error)
Post runs an http POST request with all the given parameters.
func (*Client) Put ¶
func (c *Client) Put( ctx context.Context, endpoint string, body any, marshaler Marshaler, headers map[string]string, queryParam map[string][]string, pathParams ...string, ) (res *http.Response, err error)
Put runs an http PUT request with all the given parameters.
func (*Client) Use ¶ added in v0.2.0
func (c *Client) Use( statge MiddlewareStage, middlewares ...func(context.Context, *Request), ) error
Use attaches a middleware to the client's execution chain. Middlewares added before build run before the http.Request object is created from the http method, endpoint, headers, path query parameters and body. Middlewares added before execute run before the http.Request obeject is sent.
type Configuration ¶
type Configuration struct {
// contains filtered or unexported fields
}
Configuration is a collection of options that apply to the client.
type HttpClient ¶
HttpClient defines features of an internal http clients that is used to execute http requests.
type Marshaler ¶
Marshaler defines how to convert an object into a byte array and its content type for making HTTP requests.
func NewFormMarshaler ¶
func NewFormMarshaler() Marshaler
NewXMLMarshaler creates a marshaler for application/x-www-form-urlencoded content type.
func NewJSONMarshaler ¶
func NewJSONMarshaler() Marshaler
NewJSONMarshaler creates a marshaler for application/json content type.
func NewXMLMarshaler ¶
func NewXMLMarshaler() Marshaler
NewXMLMarshaler creates a marshaler for application/xml content type.
type MemPool ¶
type MemPool struct {
// contains filtered or unexported fields
}
MemPool manages pooling memory allocations for reusing dyanmic memory.
func NewDefaultMemPool ¶
func NewDefaultMemPool() *MemPool
NewDefaultMemPool creates a memory pool with default page and pool size.
func NewMemPool ¶
NewMemPool creates a memory pool with a channel that provides byte arrays with the configured page size. The pool's channel has an upper limit of pool size.
type MemoryPool ¶
MemoryPool defines a pool that can be used to acquire memory and release memory as byte arrays.
type MiddlewareStage ¶ added in v0.2.0
type MiddlewareStage int
MiddlewareStage enumerates the stage in the request where middlewares are attached. Middlewares can be added before the http.Request object is built, or before the http.Request object is sent.
const ( MDW_BeforeBuild MiddlewareStage = iota MDW_BeforeExecute )
type Option ¶
type Option interface {
Configure(c *Configuration)
}
Option defines objects that can change a Configuration.
func UseHttpClient ¶
func UseHttpClient(client HttpClient) Option
UseHttpClient creates an option for setting the internal http client.
func UseHttpClientConstructor ¶
func UseHttpClientConstructor(constr func() HttpClient) Option
UseHttpClientConstructor creates an option for setting the constructor to create a new http client for each request.
func UseMemoryPool ¶
func UseMemoryPool(pool MemoryPool) Option
UseMemoryPool creates an option for setting the client's memory pool.
type Request ¶
type Request struct { Values map[string]any // Before Build Format string Method string Body any Marshaler Marshaler Headers map[string]string QueryParams map[string][]string PathParams []string // Before Execute Endpoint []byte Data []byte Request *http.Request Response *http.Response Errors []error // contains filtered or unexported fields }
Request stores details about the request
func (*Request) Get ¶ added in v0.2.0
Get retrieves some value from the context's Values store by a key. The operation locks the context's mutex for thread safety.
func (*Request) Lock ¶ added in v0.2.0
func (r *Request) Lock()
Lock locks the mutex within the context
func (*Request) Next ¶
func (r *Request) Next()
Next executes the next function on the function middleware on the request. If there are no more functions to call, it does nothing.
type RequestBuilder ¶ added in v0.2.0
type RequestBuilder struct {
// contains filtered or unexported fields
}
RequestBuilder allows gradual creation of http requests with functions to attach a body, headers, query parameters and path parameters.
func (*RequestBuilder) Run ¶ added in v0.2.0
Run runs the request with the client that created the request builder.
func (*RequestBuilder) WithBody ¶ added in v0.2.0
func (rb *RequestBuilder) WithBody( body any, marshaler Marshaler, ) *RequestBuilder
WithBody adds a request body and a marshaler to the request builder. If the request builder already has a request body and marshaler, they get overwritten.
func (*RequestBuilder) WithHeader ¶ added in v0.2.0
func (rb *RequestBuilder) WithHeader( key string, val string, ) *RequestBuilder
WithHeader adds a header to the request builder. If the key was already assigned some value, it gets overwritten.
func (*RequestBuilder) WithHeaders ¶ added in v0.2.0
func (rb *RequestBuilder) WithHeaders( headers map[string]string, ) *RequestBuilder
WithHeaders adds a list of headers to the request builder. If any of the keys was already assigned some value, it gets overwritten.
func (*RequestBuilder) WithPathParameters ¶ added in v0.2.0
func (rb *RequestBuilder) WithPathParameters( pathParams ...string, ) *RequestBuilder
WithPathParameter adds a path parameter to the request builder. Each parameter gets appended to the list in the builder.
func (*RequestBuilder) WithQueryParameter ¶ added in v0.2.0
func (rb *RequestBuilder) WithQueryParameter( key string, val []string, ) *RequestBuilder
WithQueryParameter adds a query parameter to the request builder. If the key was already assigned some value, it gets overwritten.
func (*RequestBuilder) WithQueryParameters ¶ added in v0.2.0
func (rb *RequestBuilder) WithQueryParameters( queryParams map[string][]string, ) *RequestBuilder
WithQueryParameters adds a list of query parameters to the request builder. If any of the keys was already assigned some value, it gets overwritten.