transport

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package transport provides HTTP transport middleware for logging, recording, and other cross-cutting concerns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTransport

func NewTransport(tracer trace.Tracer, next http.RoundTripper) http.RoundTripper

NewTransport returns an http.RoundTripper that creates an OpenTelemetry client span for every HTTP request, including OAuth token refresh calls and redirect hops. It wraps next, falling back to http.DefaultTransport when next is nil.

Use this with client.Client.Transport to ensure all HTTP calls — including those made by golang.org/x/oauth2 during token refresh — are traced:

httpClient.Transport = transport.NewTransport(tracer, httpClient.Transport)

Types

type Logging

type Logging struct {
	http.RoundTripper
	// contains filtered or unexported fields
}

Logging is an http.RoundTripper middleware that logs requests and responses.

func NewLogging

func NewLogging(w io.Writer, parent http.RoundTripper, verbose bool) *Logging

NewLogging creates a logging middleware that wraps parent. Every request and response is written to w. When verbose is true the request and response bodies are also written. If parent is nil, http.DefaultTransport is used.

func (*Logging) Payload

func (t *Logging) Payload(v interface{})

Payload writes v to the log as indented JSON.

func (*Logging) RoundTrip

func (t *Logging) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

type Recorder

type Recorder struct {
	http.RoundTripper
	// contains filtered or unexported fields
}

Recorder is an http.RoundTripper middleware that captures the status code and response headers of the most recent response. It is safe for concurrent use; each RoundTrip call overwrites the previously recorded values.

func NewRecorder

func NewRecorder(parent http.RoundTripper) *Recorder

NewRecorder wraps parent in a Recorder. If parent is nil, http.DefaultTransport is used.

func (*Recorder) Header

func (r *Recorder) Header() http.Header

Header returns a copy of the response headers recorded from the most recent response, or nil if no response has been received yet.

func (*Recorder) Reset

func (r *Recorder) Reset()

Reset clears the recorded status code and headers.

func (*Recorder) RoundTrip

func (r *Recorder) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper, recording the response status and headers before returning the response to the caller.

func (*Recorder) StatusCode

func (r *Recorder) StatusCode() int

StatusCode returns the HTTP status code recorded from the most recent response, or 0 if no response has been received yet.

Jump to

Keyboard shortcuts

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