router

package
v0.0.0-...-f0f63f4 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultServeHTTP = func(w http.ResponseWriter, r *http.Request, status int,
	err error) {
	if status >= 400 {
		if err != nil {
			http.Error(w, err.Error(), status)
		} else {
			http.Error(w, "", status)
		}
	}
}

DefaultServeHTTP is the default ServeHTTP function that receives the status and error from the function call.

Functions

This section is empty.

Types

type Handler

type Handler func(http.ResponseWriter, *http.Request) (int, error)

Handler is used to wrapper all endpoint functions so they work with generic routers.

func (Handler) ServeHTTP

func (fn Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles all the errors from the HTTP handlers.

type Mux

type Mux struct {

	// CustomServeHTTP is a settable serve function.
	CustomServeHTTP func(w http.ResponseWriter, r *http.Request, status int, err error)
	// contains filtered or unexported fields
}

Mux contains the router.

func New

func New() *Mux

New returns an instance of the router.

func (*Mux) Delete

func (m *Mux) Delete(path string, fn Handler)

Delete is a shortcut for router.Handle("DELETE", path, handle)

func (*Mux) Get

func (m *Mux) Get(path string, fn Handler)

Get is a shortcut for router.Handle("GET", path, handle)

func (*Mux) Head

func (m *Mux) Head(path string, fn Handler)

Head is a shortcut for router.Handle("HEAD", path, handle)

func (*Mux) Instance

func (m *Mux) Instance() *way.Router

Instance returns the router.

func (*Mux) Options

func (m *Mux) Options(path string, fn Handler)

Options is a shortcut for router.Handle("OPTIONS", path, handle)

func (*Mux) Param

func (m *Mux) Param(r *http.Request, param string) string

Param returns a URL parameter.

func (*Mux) Patch

func (m *Mux) Patch(path string, fn Handler)

Patch is a shortcut for router.Handle("PATCH", path, handle)

func (*Mux) Post

func (m *Mux) Post(path string, fn Handler)

Post is a shortcut for router.Handle("POST", path, handle)

func (*Mux) Put

func (m *Mux) Put(path string, fn Handler)

Put is a shortcut for router.Handle("PUT", path, handle)

func (*Mux) ServeHTTP

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

ServeHTTP routes the incoming http.Request based on method and path extracting path parameters as it goes.

Jump to

Keyboard shortcuts

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