ghostport

package module
v0.0.0-...-bfb6896 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2023 License: MIT Imports: 7 Imported by: 1

README

Ghostport - Ghost in the Transport

Package ghostport provides a http.RoundTripper for recording a number of recent requests/responses along with some other useful information for the purposes of diagnosting failures in applications that make a lot of http requests.

Constants

DefaultRingSize is 3 because that seems like a sensible number of requests to hang on to.

const DefaultRingSize = 3

Functions

func NoopCensor

func NoopCensor(in []byte) []byte

NoopCensor will simply do nothing but waste a couple of cpu cycles.

Types

type Censor

type Censor func(in []byte) []byte

Censor funcs will let you filter input bytes to remove sensitive data before it's returned.

type Option

type Option func(*Transport)

Option funcs allow the optional configuration of the Transport.

Generally you don't need to know or understand what this is, just look for the With* functions, for example: WithTransport.

func WithRequestCensor

func WithRequestCensor(c Censor) Option

WithRequestCensor permits configuring a function to censor the output of requests before being returned.

func WithResponseCensor

func WithResponseCensor(c Censor) Option

WithResponseCensor permits configuring a function to censor the output of responses before being returned.

func WithRingSize

func WithRingSize(size int) Option

WithRingSize lets you specify the size of the ring buffer used to store the round trips, default is DefaultRingSize.

func WithTransport

func WithTransport(transport http.RoundTripper) Option

WithTransport permits providing your own http.RoundTripper to be the underlying transport. If not used ghostport will use http.DefaultTransport.

type RoundTrip

type RoundTrip struct { ... }

RoundTrip stores the request, response, errors associated with dumping them, any error returned by the underlying transport and the start end/time.

func (RoundTrip) Duration

func (r RoundTrip) Duration() time.Duration

Duration time for the request.

func (RoundTrip) End

func (r RoundTrip) End() time.Time

End time of the request.

func (RoundTrip) Request

func (r RoundTrip) Request() []byte

Request bytes for request.

func (RoundTrip) RequestErr

func (r RoundTrip) RequestErr() error

RequestErr will be nil unless there was an error dumping the request.

func (RoundTrip) Response

func (r RoundTrip) Response() []byte

Response bytes for response.

func (RoundTrip) ResponseErr

func (r RoundTrip) ResponseErr() error

ResponseErr will be nil unless there was an error dumping the response.

func (RoundTrip) RoundTripErr

func (r RoundTrip) RoundTripErr() error

RoundTripErr will be nil unless there was an error returned by the underlying transport.

func (RoundTrip) Start

func (r RoundTrip) Start() time.Time

Start time of the request.

func (RoundTrip) String

func (r RoundTrip) String() string

String dumps a request into a relatively easy to grock string.

type Transport

type Transport struct { ... }

Transport implements the following interfaces;

  • http.RoundTripper to provide the ghostport.
  • fmt.Stringer so you can just print.
func New

func New(opts ...Option) *Transport

New *Transport.

func (*Transport) RoundTrip

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

RoundTrip fulfills the http.RoundTripper inteface and will record the time the trip starts, the time it ends, the request, and response from the underlying http.RoundTripper along with any errors it encounters along the way.

func (*Transport) String

func (t *Transport) String() string

String fulfills the fmt.Stringer interface.

func (*Transport) Trips

func (t *Transport) Trips() []*RoundTrip

Trips returns the list of trips stored from the ring in the order of execution.

Documentation

Overview

Package ghostport provides a http.RoundTripper for recording a number of recent requests/responses along with some other useful information for the purposes of diagnosting failures in applications that make a lot of http requests.

Index

Constants

View Source
const DefaultRingSize = 3

DefaultRingSize is 3 because that seems like a sensible number of requests to hang on to.

Variables

This section is empty.

Functions

func NoopCensor

func NoopCensor(in []byte) []byte

NoopCensor will simply do nothing but waste a couple of cpu cycles.

Types

type Censor

type Censor func(in []byte) []byte

Censor funcs will let you filter input bytes to remove sensitive data before it's returned.

type Option

type Option func(*Transport)

Option funcs allow the optional configuration of the Transport.

Generally you don't need to know or understand what this is, just look for the With* functions, for example: WithTransport.

func WithRequestCensor

func WithRequestCensor(c Censor) Option

WithRequestCensor permits configuring a function to censor the output of requests before being returned.

func WithResponseCensor

func WithResponseCensor(c Censor) Option

WithResponseCensor permits configuring a function to censor the output of responses before being returned.

func WithRingSize

func WithRingSize(size int) Option

WithRingSize lets you specify the size of the ring buffer used to store the round trips, default is DefaultRingSize.

func WithTransport

func WithTransport(transport http.RoundTripper) Option

WithTransport permits providing your own http.RoundTripper to be the underlying transport. If not used ghostport will use http.DefaultTransport.

type RoundTrip

type RoundTrip struct {
	// contains filtered or unexported fields
}

RoundTrip stores the request, response, errors associated with dumping them, any error returned by the underlying transport and the start end/time.

func (RoundTrip) Duration

func (r RoundTrip) Duration() time.Duration

Duration time for the request.

func (RoundTrip) End

func (r RoundTrip) End() time.Time

End time of the request.

func (RoundTrip) Request

func (r RoundTrip) Request() []byte

Request bytes for request.

func (RoundTrip) RequestErr

func (r RoundTrip) RequestErr() error

RequestErr will be nil unless there was an error dumping the request.

func (RoundTrip) Response

func (r RoundTrip) Response() []byte

Response bytes for response.

func (RoundTrip) ResponseErr

func (r RoundTrip) ResponseErr() error

ResponseErr will be nil unless there was an error dumping the response.

func (RoundTrip) RoundTripErr

func (r RoundTrip) RoundTripErr() error

RoundTripErr will be nil unless there was an error returned by the underlying transport.

func (RoundTrip) Start

func (r RoundTrip) Start() time.Time

Start time of the request.

func (RoundTrip) String

func (r RoundTrip) String() string

String dumps a request into a relatively easy to grock string.

type Transport

type Transport struct {
	// contains filtered or unexported fields
}

Transport implements the following interfaces; * http.RoundTripper to provide the ghostport. * fmt.Stringer so you can just print.

func New

func New(opts ...Option) *Transport

New *Transport.

func (*Transport) RoundTrip

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

RoundTrip fulfills the http.RoundTripper inteface and will record the time the trip starts, the time it ends, the request, and response from the underlying http.RoundTripper along with any errors it encounters along the way.

func (*Transport) String

func (t *Transport) String() string

String fulfills the fmt.Stringer interface.

func (*Transport) Trips

func (t *Transport) Trips() []*RoundTrip

Trips returns the list of trips stored from the ring in the order of execution.

Jump to

Keyboard shortcuts

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