roundtripper

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: MIT Imports: 4 Imported by: 0

README

RoundTripper

The roundtripper package contains functions that are used as middleware on the client side.

Getting Started

package main

import (
	"net/http"

	"github.com/gromey/proto-rest/logger"
	"github.com/gromey/proto-rest/roundtripper"
)

func main() {
	rt := roundtripper.Sequencer(
		http.DefaultTransport,
		roundtripper.DumpHttp(logger.LevelTrace),
		roundtripper.Timer(logger.LevelInfo),
		roundtripper.PanicCatcher,
	)

	hClt := new(http.Client)
	hClt.Transport = rt
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DumpHttp

func DumpHttp(logLevel logger.Level) func(http.RoundTripper) http.RoundTripper

DumpHttp dumps the HTTP request and response, and prints out with logFunc.

func PanicCatcher

func PanicCatcher(next http.RoundTripper) http.RoundTripper

PanicCatcher handles panics in http.RoundTripper.

func Sequencer

func Sequencer(baseRoundTripper http.RoundTripper, rts ...func(http.RoundTripper) http.RoundTripper) http.RoundTripper

Sequencer chains http.RoundTrippers in a chain.

func Timer

func Timer(logLevel logger.Level) func(http.RoundTripper) http.RoundTripper

Timer measures the time taken by http.RoundTripper.

Types

type Func added in v0.1.0

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

The Func type is an adapter to allow the use of ordinary functions as HTTP round trippers. If f is a function with the appropriate signature, Func(f) is a RoundTripper that calls f.

func (Func) RoundTrip added in v0.1.0

func (f Func) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip calls f(r).

Jump to

Keyboard shortcuts

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