roundtripper

package
v0.0.0-...-35d8de9 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package roundtripper contains http.RoundTripper implementations suitable for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JSONRoundTripper

type JSONRoundTripper struct {
	// Handler is called by RoundTrip with the unmarshalled JSON from an *http.Request.
	// Returns an HTTP status code and an interface{} to marshal as JSON in an *http.Response.
	Handler func(interface{}) (int, interface{})
	// Type is the reflect.Type to unmarshal *http.Request.Body into.
	// Defaults to map[string]string{}.
	Type reflect.Type
}

JSONRoundTripper implements http.RoundTripper to handle *http.Requests with a JSON body.

func (*JSONRoundTripper) RoundTrip

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

RoundTrip handles an *http.Request with a JSON body, returning an *http.Response with a JSON body. Panics on error. Implements http.RoundTripper.

type StringRoundTripper

type StringRoundTripper struct {
	// Handler is called by RoundTrip.
	// Returns an HTTP status code and a string to return in an *http.Response.
	Handler func(*http.Request) (int, string)
}

StringRoundTripper implements http.RoundTripper to handle *http.Requests.

func (*StringRoundTripper) RoundTrip

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

RoundTrip handles an *http.Request, returning an *http.Response with a string body. Panics on error. Implements http.RoundTripper.

Jump to

Keyboard shortcuts

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