option

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPClient

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

HTTPClient is primarily used to describe an *http.Client, but also supports custom implementations.

For bespoke implementations, prefer using an *http.Client with a custom transport. See http.RoundTripper for further information.

type Middleware

type Middleware = func(*http.Request, MiddlewareNext) (*http.Response, error)

Middleware is a function which intercepts HTTP requests, processing or modifying them, and then passing the request to the next middleware or handler in the chain by calling the provided MiddlewareNext function.

type MiddlewareNext

type MiddlewareNext = func(*http.Request) (*http.Response, error)

MiddlewareNext is a function which is called by a middleware to pass an HTTP request to the next stage in the middleware chain.

type RequestOption

type RequestOption = requestconfig.RequestOption

func WithAuthMode added in v0.4.0

func WithAuthMode(mode string) RequestOption

WithAuthMode selects parallel PAT or SA authentication. Tokens are opaque.

func WithAuthToken

func WithAuthToken(value string) RequestOption

WithAuthToken authenticates with a Qoder personal or service access token.

func WithBaseURL

func WithBaseURL(base string) RequestOption

WithBaseURL returns a RequestOption that sets the BaseURL for the client.

For security reasons, ensure that the base URL is trusted.

func WithCredential

func WithCredential(credential requestconfig.Credential) RequestOption

WithCredential uses the same token provider as Forward Mode. The provider is evaluated for each request; an explicit Authorization header takes precedence.

func WithHTTPClient

func WithHTTPClient(client HTTPClient) RequestOption

WithHTTPClient returns a RequestOption that changes the underlying HTTP client. Forward and Managed clients use requestconfig.DefaultHTTPClient by default.

For custom uses cases, it is recommended to provide an *http.Client with a custom http.RoundTripper as its transport, rather than directly implementing HTTPClient.

func WithHeader

func WithHeader(key, value string) RequestOption

WithHeader returns a RequestOption that sets the header value to the associated key. It overwrites any value if there was one already present.

func WithHeaderAdd

func WithHeaderAdd(key, value string) RequestOption

WithHeaderAdd returns a RequestOption that adds the header value to the associated key. It appends onto any existing values.

func WithHeaderDel

func WithHeaderDel(key string) RequestOption

WithHeaderDel returns a RequestOption that deletes the header value(s) associated with the given key.

func WithJSONDel

func WithJSONDel(key string) RequestOption

WithJSONDel returns a RequestOption that deletes the body's JSON value associated with the key. The key accepts a string as defined by the sjson format.

func WithJSONSet

func WithJSONSet(key string, value any) RequestOption

WithJSONSet returns a RequestOption that sets the body's JSON value associated with the key. The key accepts a string as defined by the sjson format.

func WithMaxRetries

func WithMaxRetries(retries int) RequestOption

WithMaxRetries returns a RequestOption that sets the maximum number of retries that the client attempts to make. When given 0, the client only makes one request. By default, the client retries two times.

WithMaxRetries panics when retries is negative.

func WithMiddleware

func WithMiddleware(middlewares ...Middleware) RequestOption

WithMiddleware returns a RequestOption that applies the given middleware to the requests made. Each middleware will execute in the order they were given.

func WithPAT

func WithPAT(value string) RequestOption

WithPAT is the Qoder spelling of WithAuthToken.

func WithQuery

func WithQuery(key, value string) RequestOption

WithQuery returns a RequestOption that sets the query value to the associated key. It overwrites any value if there was one already present.

func WithQueryAdd

func WithQueryAdd(key, value string) RequestOption

WithQueryAdd returns a RequestOption that adds the query value to the associated key. It appends onto any existing values.

func WithQueryDel

func WithQueryDel(key string) RequestOption

WithQueryDel returns a RequestOption that deletes the query value(s) associated with the key.

func WithRequestBody

func WithRequestBody(contentType string, body any) RequestOption

WithRequestBody returns a RequestOption that provides a custom serialized body with the given content type.

body accepts an io.Reader or raw []bytes.

func WithRequestTimeout

func WithRequestTimeout(dur time.Duration) RequestOption

WithRequestTimeout returns a RequestOption that sets the timeout for each request attempt. This should be smaller than the timeout defined in the context, which spans all retries.

An attempt that exceeds this timeout is retried (see WithMaxRetries) for as long as the context passed to the method is not done, so a call can take up to roughly (retries + 1) * dur plus backoff before it fails with context.DeadlineExceeded.

func WithResponseBodyInto

func WithResponseBodyInto(dst any) RequestOption

WithResponseBodyInto returns a RequestOption that overwrites the deserialization target with the given destination. If provided, we don't deserialize into the default struct.

func WithResponseInto

func WithResponseInto(dst **http.Response) RequestOption

WithResponseInto returns a RequestOption that copies the *http.Response into the given address.

Jump to

Keyboard shortcuts

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