Skip to content

Instantly share code, notes, and snippets.

@oal
Last active August 29, 2015 14:03
Show Gist options
  • Save oal/4af2d80f56ea2d6e3904 to your computer and use it in GitHub Desktop.
Save oal/4af2d80f56ea2d6e3904 to your computer and use it in GitHub Desktop.
"Strict slash" in Beego router
// Put this in your router.go
// I wasn't able to find any settings for this in Beego, so I created this middleware.
import "strings"
beego.InsertFilter("*", beego.BeforeExec, func(ctx *context.Context) {
path := ctx.Request.URL.Path
if path[len(path)-1] != '/' && strings.Index(path, "/static/") != 0 {
ctx.Redirect(301, path+"/")
}
})
@rmrio
Copy link

rmrio commented Jan 6, 2015

The correct version is:
beego.InsertFilter("*", beego.BeforeRouter, func(ctx *context.Context)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment