Skip to content
/ mm Public

mm is a middleware-middleware for multiple rules.

License

Notifications You must be signed in to change notification settings

2manymws/mm

Repository files navigation

mm Go Reference build Coverage Code to Test Ratio Test Execution Time

mm is a middleware-middleware for multiple rules.

It provides middleware that changes the middlewares used based on the request.

Usage

Prepare an instance that implements mm.Builder interface.

Then, generate the middleware ( func(next http.Handler) http.Handler ) with mm.New

package main

import (
    "log"
    "net/http"

    "github.com/2manymws/mm"
)

func main() {
    r := http.NewServeMux()
    r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte("Hello World"))
    })

    var b mm.Builder = newMyBuilder()
    m := mm.New(b)

    log.Fatal(http.ListenAndServe(":8080", m(r)))
}