mux

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package mux defines a simple API for all http multiplexers to implement.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Http

type Http struct {
	// contains filtered or unexported fields
}

Http wraps a http.ServeMux and provides some helpers around overriding the default "HTTP 404 Not Found" and "HTTP 405 Method Not Allowed" behaviour.

func NewHttp

func NewHttp(opts ...HttpOption) *Http

NewHttp initializes a request multiplexer using the standard [http.ServeMux.]

func (*Http) Handle

func (m *Http) Handle(method Method, pattern string, h http.Handler)

Handle will register the http.Handler for the given method and pattern with the underlying http.ServeMux. The method and pattern will be formatted together as "method pattern" when calling http.ServeMux.Handle.

func (*Http) ServeHTTP

func (m *Http) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface.

type HttpOption

type HttpOption func(*Http)

HttpOption defines a configuration option for Http.

func MethodNotAllowedHandler

func MethodNotAllowedHandler(h http.Handler) HttpOption

MethodNotAllowedHandler will register the given http.Handler to handle any HTTP requests whose method does not match the method registered to a pattern.

func NotFoundHandler

func NotFoundHandler(h http.Handler) HttpOption

NotFoundHandler will register the given http.Handler to handle any HTTP requests that do not match any other method-pattern combinations.

type Method

type Method string

Method defines an HTTP method expected to be used in a RESTful API.

const (
	MethodGet    Method = http.MethodGet
	MethodPut    Method = http.MethodPut
	MethodPost   Method = http.MethodPost
	MethodDelete Method = http.MethodDelete
)

Jump to

Keyboard shortcuts

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