slash

package module
v0.0.0-...-1233b61 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2017 License: MIT Imports: 2 Imported by: 0

README

GoMiddleware : Slash

Middleware that redirects to URLs either with or without a trailing slash.

Synopsis

package main

import (
	"net/http"

	"github.com/gomiddleware/slash"
)

func handler(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte(r.URL.Path))
}

func main() {
	handle := http.HandlerFunc(handler)

	http.Handle("/", handle)

	http.Handle("/docs", slash.Add(handle))
	http.Handle("/docs/", handle)

	http.Handle("/about", handle)
	http.Handle("/about/", slash.Remove(handle))

	http.ListenAndServe(":8080", nil)
}

Author

Written by Andrew Chilton for Apps Attic Ltd.

License

ISC.

(Ends)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(next http.Handler) http.Handler

Add returns middleware which checks the request's path and redirects to the same path with a trailing slash if it doesn't already have one.

func Remove

func Remove(next http.Handler) http.Handler

Remove returns middleware which checks the request's path and redirects to the same path but minus any trailing slash if it currently has one. The "/" path is ignored by this middleware.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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