rt

package module
v0.0.0-...-4efb71c Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2019 License: MIT Imports: 1 Imported by: 0

README

rt GoDoc Build Status Go Report Card

package rt provides a set of http.RoundTripper middleware for common tasks

install

go get github.com/kasperlewau/rt

usage

import (
	"net/http"
	"time"

	"github.com/kasperlewau/rt"
)

func main() {
	chain := rt.New(
		rt.UserAgent("my_ua"),
	)

	client := chain.Wrap(&http.Client{
		Timeout: 10 * time.Second,
	})

	req, _ := http.NewRequest("GET", "https://www.whatsmyua.info/api/v1/ua", nil)
	resp, _ := client.Do(req)
}

license

MIT

Documentation

Overview

package rt provides RoundTripper middleware for an *http.Client

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chain

type Chain []Tripper

Chain is a list of Trippers The chain is an effective no-op. Users must call the Wrap method on an *http.Client to utilize the Chain

func New

func New(trippers ...Tripper) Chain

New constructs a Chain of Trippers

func (Chain) Wrap

func (c Chain) Wrap(client *http.Client) *http.Client

Wrap returns a clone of the given *http.Client with its Transport set to the chain of Trippers in reverse order

type Tripper

type Tripper func(http.RoundTripper) http.RoundTripper

Tripper wraps a RoundTripper and returns a new

func Authorization

func Authorization(auth string) Tripper

UserAgent returns a Tripper that sets the Authorization header of any outgoing request

func Headers

func Headers(h http.Header) Tripper

Headers returns a Tripper that sets the given headers of any outgoing request

func UserAgent

func UserAgent(ua string) Tripper

UserAgent returns a Tripper that sets the User-Agent header of any outgoing request

type TripperFunc

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

TripperFunc does what an http.HandlerFunc does

func (TripperFunc) RoundTrip

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

Jump to

Keyboard shortcuts

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