Documentation
¶
Overview ¶
Package mux implements a request router and dispatcher for matching incoming requests to their respective handler.
Inspired by:
https://github.com/nmerouze/stack
Usage ¶
router := mux.NewRouter() router.Use(globalMiddleware1, globalMiddleware2, ...) router.Handle(method, path).Use(middleware1, middleware2, ...).Then(handler) http.ListenAndServe(addr, router) See cmd/server/main.go for example.
Index ¶
- type Mux
- func (m *Mux) DELETE(p string) *route
- func (m *Mux) GET(p string) *route
- func (m *Mux) Handle(method string, path string) *route
- func (m *Mux) NewSubRouter(prefix string) *Mux
- func (m *Mux) PATCH(p string) *route
- func (m *Mux) POST(p string) *route
- func (m *Mux) PUT(p string) *route
- func (m *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (m *Mux) Use(middlewares ...middleware) *Mux
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Mux ¶
type Mux struct {
// contains filtered or unexported fields
}
func (*Mux) NewSubRouter ¶
NewSubRouter creates a new sub-router with the given prefix. The returned Mux shares the same underlying ServeMux as the parent, so all handlers are registered on the same ServeMux. The prefix is prepended to all routes registered via HandleFunc on the sub-router.
Example:
router := NewMux()
apiRouter := router.NewSubRouter("/api/v0")
apiRouter.HandleFunc("/hello", HelloHandler)
Click to show internal directories.
Click to hide internal directories.