Documentation
¶
Overview ¶
Package interceptor provides an HTTP interceptor system. It allows composing middleware interceptors that can inspect, modify, retry, or short-circuit HTTP requests and responses flowing through a standard http.RoundTripper.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HandlerFunc ¶
HandlerFunc represents the next step in the interceptor chain. It takes an HTTP request and returns a response or error.
type Middleware ¶
Middleware defines an interceptor. It receives the outgoing request and a next function representing the next processing step in the interceptor chain.
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport implements http.RoundTripper by running a chain of interceptors in front of a default transport.
func NewTransport ¶
func NewTransport(defaultTransport http.RoundTripper, interceptors ...Middleware) *Transport
NewTransport creates a new Transport with the given default RoundTripper and interceptors. If defaultTransport is nil, http.DefaultTransport is used. Interceptors are executed in the order provided.
// Using the default transport:
client := &http.Client{
Transport: interceptor.NewTransport(nil, AInterceptor, BInterceptor),
}
// Using a custom default transport:
client := &http.Client{
Transport: interceptor.NewTransport(customTransport, AInterceptor, BInterceptor),
}
func (*Transport) RoundTrip ¶
RoundTrip executes the interceptor chain. The underlying transport is reached only if each interceptor calls next.
func (*Transport) Use ¶
func (t *Transport) Use(interceptors ...Middleware) *Transport
Use appends one or more interceptors to the chain. They are appended after any interceptors already registered.
t := interceptor.NewTransport(nil, AuthInterceptor).Use(MetricsInterceptor)