Documentation
¶
Overview ¶
Package decorator provides a framework for composing HTTP middleware using the decorator pattern.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decorate ¶
func Decorate(t http.RoundTripper, rts ...Decorator) http.RoundTripper
Decorate composes middleware in the intended order of execution.
Ordering rules:
- The FIRST decorator argument becomes the OUTERMOST layer and runs first.
- The LAST decorator argument is closest to the base transport and runs last.
- Decorators are applied right-to-left internally to achieve the above.
Example:
// Execution order: Logging -> Retry -> Base Transport
transport := Decorate(
http.DefaultTransport,
Logging(), // runs first
Retry(), // runs second
)
Tip: Keep cross-cutting concerns that need to observe everything (e.g., Debug) on the outside, and components that mutate the request just before sending (e.g., Auth/UserAgent) closer to the transport.
Types ¶
type Decorator ¶
type Decorator func(http.RoundTripper) http.RoundTripper
Decorator represents an HTTP middleware layer that wraps an http.RoundTripper. The returned RoundTripper MUST call the supplied one to continue the chain.
Click to show internal directories.
Click to hide internal directories.