client

package
v0.0.0-...-d83bd77 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2025 License: Apache-2.0 Imports: 13 Imported by: 8

Documentation

Overview

package client provides HTTP request handling functionality with various middleware options.

Index

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 manages HTTP requests with various middleware options.

func NewClient

func NewClient(opts ...Option) *Client

NewClient creates a new Client instance with default settings.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request) (*http.Response, error)

Do performs an HTTP request with the specified options.

func (*Client) NewRequest

func (c *Client) NewRequest() *Request

NewRequest creates a new Request with default options.

type MarshalFunc

type MarshalFunc func(interface{}) ([]byte, error)

MarshalFunc is a function type that matches standard marshal functions.

type Option

type Option func(*Client)

Option is a function type that modifies the Client configuration.

func WithLogger

func WithLogger(logger logger.Logger) Option

WithLogger sets the logger for the Client and its middleware.

func WithMarshalFunc

func WithMarshalFunc(fn MarshalFunc) Option

WithMarshalFunc sets the marshal function for the Client.

func WithMiddleware

func WithMiddleware(middleware middleware.Middleware) Option

WithMiddleware adds or updates the middleware for the Client with a specified priority.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout sets the timeout for the Client.

func WithUnmarshalFunc

func WithUnmarshalFunc(fn UnmarshalFunc) Option

WithUnmarshalFunc sets the unmarshal function for the Client.

type Query

type Query map[string][]string

Query maps a string key to a list of values. It is typically used for query parameters and form values. Unlike in the http.Header map, the keys in a Query map are case-sensitive.

func (Query) Add

func (v Query) Add(key, value string)

Add appends a value to the list of values associated with the key. It appends to any existing values associated with the key.

func (Query) Encode

func (v Query) Encode() string

Encode converts the Query into a URL-encoded string. The resulting string is in "URL encoded" form ("bar=baz&foo=quux") with keys sorted alphabetically.

func (Query) Get

func (v Query) Get(key string) string

Get retrieves the first value associated with the given key. If there are no values associated with the key, Get returns the empty string. To access multiple values, use the map directly.

func (Query) Set

func (v Query) Set(key, value string)

Set assigns the key to a single value. It replaces any existing values associated with the key.

type Request

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

Request helps build requests using method chaining.

func (*Request) Body

func (rb *Request) Body(body []byte) *Request

Body sets the body of the request.

func (*Request) Build

func (rb *Request) Build(ctx context.Context) (*http.Request, error)

Build returns the final http.Request for execution.

func (*Request) Do

func (rb *Request) Do(ctx context.Context) (*http.Response, error)

Do executes the request and returns the raw http.Response.

func (*Request) Header

func (rb *Request) Header(key, value string) *Request

Header adds a header to the request.

func (*Request) MarshalBody

func (rb *Request) MarshalBody(body interface{}) *Request

MarshalBody sets the body of the request after marshaling the provided struct.

func (*Request) MarshalWith

func (rb *Request) MarshalWith(fn MarshalFunc) *Request

MarshalWith sets the marshal function for the request body.

func (*Request) Method

func (rb *Request) Method(method string) *Request

Method sets the HTTP method for the request.

func (*Request) Query

func (rb *Request) Query(key, value string) *Request

Query adds a query parameter to the request.

func (*Request) Result

func (rb *Request) Result(result interface{}) *Request

Result sets the result to unmarshal the response into.

func (*Request) URL

func (rb *Request) URL(url string) *Request

URL sets the URL for the request.

func (*Request) UnmarshalWith

func (rb *Request) UnmarshalWith(fn UnmarshalFunc) *Request

UnmarshalWith sets the unmarshal function for the response.

type UnmarshalFunc

type UnmarshalFunc func([]byte, interface{}) error

UnmarshalFunc is a function type that matches standard unmarshal functions.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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