renanbastos93 / redirect

🧬 Redirect middleware for Fiber

Home Page:https://github.com/gofiber/fiber

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Install

go get -u github.com/gofiber/fiber
go get -u github.com/gofiber/redirect

Example

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",
    },
    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)
}

Test

curl http://localhost:3000/old
curl http://localhost:3000/old/hello

About

🧬 Redirect middleware for Fiber

https://github.com/gofiber/fiber

License:MIT License


Languages

Language:Go 100.0%