servemux

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2020 License: MIT Imports: 4 Imported by: 0

README

varouter/servemux

Description

Package servemux implements an API-compatible http.ServeMux alternative that uses Varouter internally. It serves mostly as an example of how to wrap Varouter into a custom mux.

Documentation

Overview

Package servemux implements an API-compatible http.ServeMux alternative that uses Varouter internally. It serves mostly as an example of how to wrap Varouter into a custom mux.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Placeholders

func Placeholders(r *http.Request) varouter.Vars

Placeholders is a helper method that retrieves Placeholders map from the context of a *http.Request. If no Placeholder map was stored in the request a nil Placeholders map is returned.

Types

type ServeMux

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

ServeMux is a serve mux that is API identical to http.ServeMux but is using varouter internally. The behaviour also mirrors Varouter's behaviour.

Additionally, it stores any parsed Placeholders in a Placeholder map in the request context which is accessible via Placeholders helper function.

func NewServeMux

func NewServeMux() *ServeMux

NewServeMux returns a new ServeMux instance.

func (*ServeMux) Handle

func (mux *ServeMux) Handle(pattern string, handler http.Handler)

Handle registers the handler for the given pattern. If a handler already exists for pattern, Handle panics.

func (*ServeMux) HandleFunc

func (mux *ServeMux) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

HandleFunc registers the handler function for the given pattern.

func (*ServeMux) Handler

func (mux *ServeMux) Handler(r *http.Request) (h http.Handler, pattern string)

Handler returns the handler to use for the given request, consulting r.URL.Path. It always returns a non-nil handler.

If there is no registered handler that applies to the request, Handler returns a “page not found” handler and an empty pattern.

func (*ServeMux) ServeHTTP

func (mux *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP dispatches the request to the handler whose pattern most closely matches the request URL.

Jump to

Keyboard shortcuts

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