fakehttp

package
v0.9.15 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package fakehttp provides a fake HTTP server for tests that have dependencies using HTTP clients.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeResponse

func DecodeResponse(resp *http.Response, v interface{}) error

DecodeResponse decodes the HTTP Response.Body JSON.

func DefaultHandler

func DefaultHandler(req *http.Request) (interface{}, error)

DefaultHandler is a default HTTP request handler that returns a nil body.

Types

type HTTP

type HTTP struct {
	// Handler is handler for HTTP requests.
	Handler Handler
	// Server is the HTTP server. Uses handler for handling requests.
	Server *httptest.Server
	// Client is the HTTP client connected to the HTTP server.
	Client *http.Client
}

HTTP provides an HTTP server routing calls to its handler and a client connected to it.

func New

func New() (*HTTP, func() error)

New creates a new HTTP server and client.

type Handler

type Handler func(req *http.Request) (body interface{}, err error)

Handler handles HTTP requests.

type PrefixHandlers

type PrefixHandlers map[string]Handler

PrefixHandlers demuxes calls based on URL path prefix. The first handler whose prefix matches will be called.

func (PrefixHandlers) Handler

func (p PrefixHandlers) Handler(req *http.Request) (body interface{}, err error)

Handler handles HTTP requests.

Jump to

Keyboard shortcuts

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