http

package
v0.0.0-...-e1e9d1d Latest Latest
Warning

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

Go to latest
Published: May 20, 2021 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package http defines the standard interfaces for HTTP server and client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyMiddleware

func ApplyMiddleware(h http.Handler, mw ...Middleware) http.Handler

ApplyMiddleware applies the provided list of middleware to the HTTP handler h, in order - i.e. the first middleware is applied to the next, which is applied to the next, etc. until the last one which is applied to h.

Types

type Client

type Client interface {
	// Do executes the request and returns the response or an error. The context
	// is not part of the signature, as it is part of the HTTP request struct.
	Do(req *http.Request) (*http.Response, error)
}

Client defines the method for an HTTP client.

type Middleware

type Middleware func(http.Handler) http.Handler

A Middleware is a function that takes a HTTP handler and returns another HTTP handler, with some behaviour added.

type MockClient

type MockClient struct {
	DoFunc func(*http.Request) (*http.Response, error)
}

MockClient is a test mock for the Client interface.

func (*MockClient) Do

func (m *MockClient) Do(req *http.Request) (*http.Response, error)

type MockServer

type MockServer struct {
	MountFunc          func(string, http.Handler) error
	ListenAndServeFunc func(context.Context) error
}

MockServer is a test mock for the Server interface.

func (*MockServer) ListenAndServe

func (m *MockServer) ListenAndServe(ctx context.Context) error

func (*MockServer) Mount

func (m *MockServer) Mount(path string, h http.Handler) error

type Server

type Server interface {
	// Mount mounts an HTTP handler at the specified path. The exact semantics of
	// the operation is implementation-specific.
	Mount(path string, handler http.Handler) error

	// ListenAndServe starts the HTTP server. The context is used to signal
	// graceful shutdown of the server when cancelled. It should also be used as
	// base context for requests, but this is implementation-specific.
	ListenAndServe(ctx context.Context) error
}

Server defines the methods for an HTTP server.

Directories

Path Synopsis
Package httpssn defines the standard interfaces for HTTP sessions, which may be implemented as cookies, file-system based, etc.
Package httpssn defines the standard interfaces for HTTP sessions, which may be implemented as cookies, file-system based, etc.

Jump to

Keyboard shortcuts

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