Last active
April 11, 2020 07:39
-
-
Save renanbastos93/9d5e50b8cffd1c933d96bd80567848ec to your computer and use it in GitHub Desktop.
Using redirect middleware with GoFiber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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