Back to godoc.org

Package roundtripper

v0.0.0-...-1557bcf
Latest Go to latest

The latest major version is .

Published: Aug 13, 2020 | License: Apache-2.0 | Module: github.com/luci/luci-go

Overview

Package roundtripper contains http.RoundTripper implementations suitable for testing.

Index

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.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier