router

package module
v0.0.0-...-79cd767 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2022 License: MIT Imports: 4 Imported by: 1

README

router

Simple HTTP Go router based on this gist by Ben Hoyt.

router := router.New()

router.HandlerFunc(http.MethodPost, "/v1/users", registerUserHandler)
router.HandlerFunc(http.MethodGet, "/v1/users/:id", showUserHandler)

router.NotFound = http.HandlerFunc(customNotFoundHandler)
router.MethodNotAllowed = http.HandlerFunc(customMethodNotAllowedHandler)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Param

func Param(r *http.Request, key string) string

func Params

func Params(ctx context.Context) map[string]string

Types

type Router

type Router struct {
	NotFound         http.HandlerFunc
	MethodNotAllowed http.HandlerFunc
	// contains filtered or unexported fields
}

func New

func New() *Router

func (*Router) Handle

func (rt *Router) Handle(method string, pattern string,
	handler http.Handler)

func (*Router) HandleAll

func (rt *Router) HandleAll(pattern string,
	handler http.Handler)

func (*Router) HandleAllFunc

func (rt *Router) HandleAllFunc(pattern string,
	handler func(http.ResponseWriter, *http.Request))

func (*Router) HandleFunc

func (rt *Router) HandleFunc(method string, pattern string,
	handler func(http.ResponseWriter, *http.Request))

func (*Router) ServeHTTP

func (rt *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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