Skip to content

Instantly share code, notes, and snippets.

@renanbastos93
Last active April 11, 2020 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renanbastos93/9d5e50b8cffd1c933d96bd80567848ec to your computer and use it in GitHub Desktop.
Save renanbastos93/9d5e50b8cffd1c933d96bd80567848ec to your computer and use it in GitHub Desktop.
Using redirect middleware with GoFiber
package main
import (
"github.com/gofiber/fiber"
"github.com/gofiber/redirect"
)
func main() {
app := fiber.New()
app.Use(redirect.New(redirect.Config{
Rules: map[string]string{
"/old": "/new",
"/old/*": "/new/$1",
"/wow": "https://fiber.wiki",
},
StatusCode: 301,
}))
app.Get("/new", func(c *fiber.Ctx) {
c.Send("Hello, World!")
})
app.Get("/new/*", func(c *fiber.Ctx) {
c.Send("Wildcard: ", c.Params("*"))
})
app.Listen(3000)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment