Skip to content

goflash/middleware-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Middleware template for the GoFlash web framework

Features

  • 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

Installation

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.

Quick start

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))
}

Configuration

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

  • 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/

Testing

Run tests with coverage:

./scripts/coverage.sh

Versioning and compatibility

  • Module path: github.com/goflash/middleware-template
  • Requires Go 1.23+

Contributing

Issues and PRs are welcome. Please run tests before submitting.

License

MIT

About

Starter template for building middleware for the GoFlash web framework.

Topics

Resources

Stars

Watchers

Forks

Sponsor this project