https://github.com/novrin/midway
The Go package for arranging your HTTP middleware.
https://github.com/novrin/midway
go golang golang-package http-middleware middleware
Last synced: 6 days ago
JSON representation
The Go package for arranging your HTTP middleware.
- Host: GitHub
- URL: https://github.com/novrin/midway
- Owner: novrin
- License: mit
- Created: 2023-12-29T05:16:05.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-03T04:32:15.000Z (about 2 years ago)
- Last Synced: 2024-01-03T09:23:50.450Z (about 2 years ago)
- Topics: go, golang, golang-package, http-middleware, middleware
- Language: Go
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# midway
[](https://pkg.go.dev/github.com/novrin/midway)

[](https://goreportcard.com/report/github.com/novrin/midway)
`midway` is a micro Go package for arranging your HTTP middleware.
### Installation
```shell
go get github.com/novrin/midway
```
## Usage
A `Queue` returns a `Middleware` where the slice of given middlewares are applied first-in-first-out. The last middleware in the slice will execute first.
```go
package main
import (
"net/http"
"github.com/novrin/midway"
)
func main() {
// Use Queue to arrange middleware to execute secureHeaders first.
queued := midway.Queue(corsHeaders, secureHeaders)
app := http.HandlerFunc(hello)
http.ListenAndServe(":1313", queued(app))
// serves secureHeaders(corsHeaders(app))
}
```
A `Stack` returns a `Middleware` where the slice of given middlewares are applied last-in-first-out. The first middleware in the slice will execute first.
```go
package main
import (
"net/http"
"github.com/novrin/midway"
)
func main() {
// Use Stack to arrange middleware to execute corsHeaders first.
stacked := midway.Stack(corsHeaders, secureHeaders)
app := http.HandlerFunc(hello)
http.ListenAndServe(":1313", stacked(app))
// serves corsHeaders(secureHeaders(app))
}
```
## License
Copyright (c) 2023-present [novrin](https://github.com/novrin)
Licensed under [MIT License](./LICENSE)