- Minimal example middleware (
ExampleMiddleware
) showing the pattern - Runnable example app under
examples/basic
- Go module with Go 1.23 toolchain
- Ready to copy/fork for new middleware in the GoFlash ecosystem
go get github.com/goflash/middleware-template
Go version: requires Go 1.23+. The module sets go 1.23
and can be used with newer Go versions.
This is the minimal usage from examples/basic
:
package main
import (
"log"
"net/http"
"github.com/goflash/middleware-template"
"github.com/goflash/flash/v2"
)
func main() {
app := flash.New()
// Use the example middleware
app.Use(example.ExampleMiddleware)
// Define a simple route
app.GET("/", func(c flash.Ctx) error {
return c.String(http.StatusOK, "ok")
})
log.Fatal(http.ListenAndServe(":8080", app))
}
This template doesn’t prescribe configuration. Customize the middleware to your needs by editing ExampleMiddleware
(or replacing it with your own). A typical middleware should:
- Accept and return a
flash.Handler
- Optionally read/write values on the request context
- Call
next(c)
to pass control to the next handler
examples/basic
: minimal setup showing how to plug the middleware into a GoFlash app and serve a simple route.
Run the example locally:
cd examples/basic
go run .
Then in another shell:
curl -s localhost:8080/
Run tests with coverage:
./scripts/coverage.sh
- Module path:
github.com/goflash/middleware-template
- Requires Go 1.23+
Issues and PRs are welcome. Please run tests before submitting.
MIT