https://github.com/reiver/go-pathmux
Package pathmux provides a path oriented ("middleware") HTTP handler, which can hand-off to other HTTP handler for each path, for the Go programming language's built-in "net/http" library.
https://github.com/reiver/go-pathmux
http http-middleware
Last synced: 7 months ago
JSON representation
Package pathmux provides a path oriented ("middleware") HTTP handler, which can hand-off to other HTTP handler for each path, for the Go programming language's built-in "net/http" library.
- Host: GitHub
- URL: https://github.com/reiver/go-pathmux
- Owner: reiver
- License: mit
- Created: 2019-06-21T00:42:27.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-01-13T18:43:25.000Z (about 1 year ago)
- Last Synced: 2025-06-04T13:29:20.357Z (9 months ago)
- Topics: http, http-middleware
- Language: Go
- Homepage: https://godoc.org/github.com/reiver/go-pathmux
- Size: 28.3 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-pathmux
Package **pathmux** provides a path oriented route ("middleware") HTTP handler, which can hand-off to other HTTP handler for each path,
for the Go programming language's built-in `"net/http"` library.
Package pathmux is a HTTP request router, and dispatcher.
The name mux stands for "HTTP request multiplexer".
Similar to the built-in standard http.ServeMux in the "net/http" package,
pathmux.Mux matches incoming requests against a list of registered routes
and calls a handler for the route that matches the URL or other conditions.
## Documention
Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-pathmux
[](https://godoc.org/github.com/reiver/go-pathmux)
## Example
```go
import "github.com/reiver/go-pathmux"
// ...
var mux pathmux.Mux
err := mux.HandlePath(homeHandler, "/")
err := mux.HandlePath(productsHandler, "/products")
err := mux.HandlePath(articlesHandler, "/articles")
err := mux.HandlePattern(productPatternHandler, "/products/{key}")
err := mux.HandlePattern(articleCategoryPatternHandler, "/articles/{category}/")
err := mux.HandlePattern(articlePatternHandler, "/articles/{category}/{article_id}")
// handles: "/app", "/app/", "/app/apple", "/app/banana", "/app/banana/", "/app/banana/peel.jpeg", "/app/cherry", etc.
err := mux.HandleDirectory(homeHandler, "/app")
// ...
err := http.ListenAndServe(":8080", mux)
```
## Import
To import package **pathmux** use `import` code like the follownig:
```
import "github.com/reiver/go-pathmux"
```
## Installation
To install package **pathmux** do the following:
```
GOPROXY=direct go get github.com/reiver/go-pathmux
```
## Author
Package **pathmux** was written by [Charles Iliya Krempeaux](http://reiver.link)