requestconfig

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplySecurity added in v0.12.1

func ApplySecurity(r RequestConfig)

func ExecuteNewRequest

func ExecuteNewRequest(ctx context.Context, method string, u string, body any, dst any, opts ...RequestOption) error

Types

type HTTPDoer

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

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

type PreRequestOptionFunc

type PreRequestOptionFunc func(*RequestConfig) error

func (PreRequestOptionFunc) Apply

type RequestConfig

type RequestConfig struct {
	MaxRetries     int
	RequestTimeout time.Duration
	Context        context.Context
	Request        *http.Request
	BaseURL        *url.URL
	// DefaultBaseURL will be used if BaseURL is not explicitly overridden using
	// WithBaseURL.
	DefaultBaseURL     *url.URL
	CustomHTTPDoer     HTTPDoer
	HTTPClient         *http.Client
	Middlewares        []middleware
	ProjectAccessToken string
	TeamAccessToken    string
	WebhookKey         string
	// Configure which security scheme(s) should be enabled for this request
	Security Security
	// If ResponseBodyInto not nil, then we will attempt to deserialize into
	// ResponseBodyInto. If Destination is a []byte, then it will return the body as
	// is.
	ResponseBodyInto any
	// ResponseInto copies the \*http.Response of the corresponding request into the
	// given address
	ResponseInto **http.Response
	Body         io.Reader
}

RequestConfig represents all the state related to one request.

Editing the variables inside RequestConfig directly is unstable api. Prefer composing the RequestOption instead if possible.

func NewRequestConfig

func NewRequestConfig(ctx context.Context, method string, u string, body any, dst any, opts ...RequestOption) (*RequestConfig, error)

func PreRequestOptions

func PreRequestOptions(opts ...RequestOption) (RequestConfig, error)

PreRequestOptions is used to collect all the options which need to be known before a call to [RequestConfig.ExecuteNewRequest], such as path parameters or global defaults. PreRequestOptions will return a RequestConfig with the options applied.

Only request option functions of type PreRequestOptionFunc are applied.

func (*RequestConfig) Apply

func (cfg *RequestConfig) Apply(opts ...RequestOption) error

func (*RequestConfig) Clone

func (cfg *RequestConfig) Clone(ctx context.Context) *RequestConfig

func (*RequestConfig) Execute

func (cfg *RequestConfig) Execute() (err error)

type RequestOption

type RequestOption interface {
	Apply(*RequestConfig) error
}

func WithDefaultBaseURL

func WithDefaultBaseURL(baseURL string) RequestOption

WithDefaultBaseURL returns a RequestOption that sets the client's default Base URL. This is always overridden by setting a base URL with WithBaseURL. WithBaseURL should be used instead of WithDefaultBaseURL except in internal code.

func WithProjectAccessTokenSecurity added in v0.12.1

func WithProjectAccessTokenSecurity() RequestOption

WithProjectAccessTokenSecurity() should only be used within a method, not provided to at the client-level.

func WithSecurity added in v0.12.1

func WithSecurity(security Security) RequestOption

func WithTeamAccessTokenSecurity added in v0.12.1

func WithTeamAccessTokenSecurity() RequestOption

WithTeamAccessTokenSecurity() should only be used within a method, not provided to at the client-level.

type RequestOptionFunc

type RequestOptionFunc func(*RequestConfig) error

func (RequestOptionFunc) Apply

type Security added in v0.12.1

type Security struct {
	ProjectAccessToken bool
	TeamAccessToken    bool
}

Jump to

Keyboard shortcuts

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