decorator

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2025 License: MIT Imports: 1 Imported by: 0

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.

type TransportFunc

type TransportFunc func(*http.Request) (*http.Response, error)

TransportFunc implements the RoundTripper interface.

func (TransportFunc) RoundTrip

func (tf TransportFunc) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip just calls the original function.

Jump to

Keyboard shortcuts

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