slash

package
v0.0.0-...-9f9aa42 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package slash provides a trailing slash remover handler for the fasthttp-routing package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Remover

func Remover(status int) routing.Handler

Remover returns a handler that removes the trailing slash (if any) from the requested URL. The handler will redirect the browser to the new URL without the trailing slash. The status parameter should be either fasthttp.StatusMovedPermanently (301) or fasthttp.StatusFound (302), which is to be used for redirecting GET requests. For other requests, the status code will be fasthttp.StatusTemporaryRedirect (307). If the original URL has no trailing slash, the handler will do nothing. For example,

import (
    "github.com/naharp/fasthttp-routing"
    "github.com/naharp/fasthttp-routing/slash"
    "github.com/valyala/fasthttp"
)

r := routing.New()
r.Use(slash.Remover(fasthttp.StatusMovedPermanently))

Note that Remover relies on HTTP redirection to remove the trailing slashes. If you do not want redirection, please set `Router.IgnoreTrailingSlash` to be true without using Remover.

Types

This section is empty.

Jump to

Keyboard shortcuts

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