chiMiddleware

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

README

chiMiddleware

chiMiddleware contains middleware helpers intended for use with go-chi/chi.

Middleware

  • HandleHTMLMinification() func(http.Handler) http.Handler
    • Minifies HTML responses when Content-Type contains text/html.
    • Uses tdewolff/minify.
  • HandleHTTPMethodConversion(next http.Handler) http.Handler
    • Converts incoming POST/GET requests to PUT or DELETE if the form contains _method=PUT or _method=DELETE.
  • HandleBrotli(next http.Handler) http.Handler
    • Brotli support. (Currently incomplete: it sets up an encoder but does not call next.)

Example (chi)

import (
    "net/http"

    "github.com/go-chi/chi/v5"
    "github.com/mt1976/frantic-core/chiMiddleware"
)

func router() http.Handler {
    r := chi.NewRouter()

    r.Use(chiMiddleware.HandleHTMLMinification())
    r.Use(chiMiddleware.HandleHTTPMethodConversion)

    return r
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleBrotli

func HandleBrotli(next http.Handler) http.Handler

func HandleHTMLMinification

func HandleHTMLMinification() func(http.Handler) http.Handler

HandleHTMLMinification returns a chi middleware that minifies HTML responses

func HandleHTTPMethodConversion

func HandleHTTPMethodConversion(next http.Handler) http.Handler

handleHTTPMethodConversion is a middleware component that checks for the combination of a POST method with a form field named _method having a value of PUT. POST method with a form field named _method having a value of DELETE. It converts the request method to PUT or DELETE accordingly. This middleware should be used before any handlers that require PUT or DELETE methods to function correctly. It is typically used in web applications that need to support RESTful operations via HTML forms. It is designed to be used with the Chi router, but can be adapted for other routers It should run early in the middleware stack.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL