middleware

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2015 License: MIT Imports: 8 Imported by: 0

README

Middleware Build Status GoDoc GoCover

A collection of HTTP middleware/Handler function for use with Go's net/http package. Compatible with Goji, Gorilla, Negroni & net/http (amongst many others).

Start using it

  • Installation
go get github.com/jeevatkm/middleware
                   OR
go get gopkg.in/jeevatkm/middleware.v0
  • Import it in your code
import "github.com/jeevatkm/middleware"
                   OR
import "gopkg.in/jeevatkm/middleware.v0"

Examples

Refer examples

Vanilla net/http
func main() {
	homeHandler := http.HandlerFunc(home)

	// Adding Minify middleware
	// Note: If you use any Gzip middleware, add Minify middleware after that
	http.Handle("/", middleware.Minify(homeHandler))

	log.Println("Starting server at localhost:8000")
	http.ListenAndServe(":8000", nil)
}
Goji web framework
func main() {
	// Adding Minify middleware
	// Note: If you use any Gzip middleware, add Minify middleware after that
	goji.Use(middleware.Minify)

	goji.Get("/", gojiHome)
	goji.Serve()
}
Gorilla Mux
func main() {
	r := mux.NewRouter()
	r.HandleFunc("/", gorillaHome)

	// Adding Minify middleware
	// Note: If you use any Gzip middleware, add Minify middleware after that
	http.Handle("/", middleware.Minify(r))

	log.Println("Starting server at localhost:8000")
	http.ListenAndServe(":8000", nil)
}
Negroni web middleware
func main() {
	mux := http.NewServeMux()
	mux.HandleFunc("/", negroniHome)

	n := negroni.Classic()

	// Adding Minify middleware
	n.UseHandler(middleware.Minify(mux))

	n.Run(":8000")
}

License

Middleware released under MIT License

Documentation

Overview

Package middleware provides a collection of HTTP middleware/Handler function for use with Go's net/http package, in other words any framework supporting http.Handler

  • Minify middleware using 'tdewolff/minify'

  • Options middleware

    import "github.com/jeevatkm/middleware" OR import "gopkg.in/jeevatkm/middleware.v0"

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Minify

func Minify(h http.Handler) http.Handler

Minify middleware is simple and generic using 'tdewolff/minify' package. Middleware minifies HTML, Inline CSS and Inline JS. Compatible with Goji, Gorilla, Gin & net/http (amongst many others). Refer: https://github.com/jeevatkm/middleware/examples

Types

This section is empty.

Directories

Path Synopsis
Example for How to use with Goji micro web framework.
Example for How to use with Goji micro web framework.

Jump to

Keyboard shortcuts

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