https://github.com/sharpvik/mux
Package sharpvik/mux seeks to provide customizable and convenient internal routing for Go's http.Server.
https://github.com/sharpvik/mux
Last synced: about 2 months ago
JSON representation
Package sharpvik/mux seeks to provide customizable and convenient internal routing for Go's http.Server.
- Host: GitHub
- URL: https://github.com/sharpvik/mux
- Owner: sharpvik
- License: mpl-2.0
- Created: 2020-05-10T23:35:11.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-03-12T02:14:56.000Z (almost 5 years ago)
- Last Synced: 2025-01-16T18:29:42.576Z (about 1 year ago)
- Language: Go
- Homepage:
- Size: 171 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Package sharpvik/mux
This package seeks to provide customizable and convenient internal routing for
Go's `http.Server`.
When building a server-side app or a REST API, you may wish to implement
complex routing mechanisms that allow you to effectively process incoming
requests by checking its signature against different routes with preset filters.
There already exist a few packages that provide this functionality. However,
there is a catch: those packages are written as though the only things your
handler functions are going to be working with are `http.ResponseWriter` and
`http.Request` sent by the user. In reality, you may wish to query a database
and/or log some data through `log.Logger`. Of course, there are ways to allow
function to acces those interfaces via a global variable or something like that,
but those are a pain to write tests for.
In this package, you can find the Router sturct that is written in a way that
resolves those problems by supporting the router-embedded context.
## Theory
Mux allows you to build flexible and fairly complex routing schemas by giving
you the `Router`. To create new `Router` you should use the `New` function.
```go
func New() *Router
```
Having a single `Router` may be exactly what you want, but it is unlikely that
you decided to use this package for such basic use case. The _cool_ things come
when you make _more_ `Router`s! Or, to be more precise, more `Subrouter`s.
```go
func (rtr *Router) Subrouter() *Router
```
## License
Use of this source code is governed by the _Mozilla Public License Version 2.0_
that can be found in the [LICENSE](LICENSE) file.