httpclient

package
v0.0.0-...-ff1d90d Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientOption

type ClientOption func(*HttpClient)

Client options

func WithHttpHeaders

func WithHttpHeaders(headers http.Header) ClientOption

func WithHttpTimeout

func WithHttpTimeout(timeout time.Duration) ClientOption

type HttpClient

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

func NewHttpClient

func NewHttpClient(baseURL string, opts ...ClientOption) *HttpClient

Create a new HTTP client

func (*HttpClient) Close

func (c *HttpClient) Close()

Close closes the idle connections of the underlying HTTP client.

The client can be reused after closing as per the http.Client documentation.

func (*HttpClient) Delete

func (c *HttpClient) Delete(ctx context.Context, path string, opts ...RequestOption) (*HttpResponse, error)

func (*HttpClient) Get

func (c *HttpClient) Get(ctx context.Context, path string, opts ...RequestOption) (*HttpResponse, error)

Request methods

func (*HttpClient) Patch

func (c *HttpClient) Patch(ctx context.Context, path string, body isHttpBody, opts ...RequestOption) (*HttpResponse, error)

func (*HttpClient) Post

func (c *HttpClient) Post(ctx context.Context, path string, body isHttpBody, opts ...RequestOption) (*HttpResponse, error)

func (*HttpClient) Put

func (c *HttpClient) Put(ctx context.Context, path string, body isHttpBody, opts ...RequestOption) (*HttpResponse, error)

type HttpResponse

type HttpResponse struct {
	Status     string        `json:"status"`
	StatusCode int           `json:"status_code"`
	Headers    http.Header   `json:"headers"`
	Body       []byte        `json:"body"`
	Request    *http.Request `json:"request"`
}

func (*HttpResponse) DecodeJSON

func (r *HttpResponse) DecodeJSON(v interface{}) error

func (*HttpResponse) String

func (r *HttpResponse) String() string

type JsonBody

type JsonBody map[string]interface{}

type MultipartBody

type MultipartBody struct {
	*multipart.Writer
	// contains filtered or unexported fields
}

func NewMultipartBody

func NewMultipartBody() *MultipartBody

type RequestOption

type RequestOption func(*requestOptions)

func WithHttpQueryParams

func WithHttpQueryParams(params map[string]string) RequestOption

func WithHttpRetries

func WithHttpRetries(retries int, wait time.Duration) RequestOption

func WithRequestHttpHeaders

func WithRequestHttpHeaders(headers http.Header) RequestOption

type UrlEncodedBody

type UrlEncodedBody struct {
	url.Values
}

func NewUrlEncodedBody

func NewUrlEncodedBody() *UrlEncodedBody

Jump to

Keyboard shortcuts

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