10000 GitHub - gofiber/redirect at v2.1.31
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on May 19, 2023. It is now read-only.

gofiber/redirect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redirect

Release Discord Test Security Linter

Install

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

Example

package main

import (
  "github.com/gofiber/fiber/v2"
  "github.com/gofiber/redirect/v2"
)

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) error {
    return c.SendString("Hello, World!")
  })
  app.Get("/new/*", func(c *fiber.Ctx) error {
    return c.SendString("Wildcard: " + c.Params("*"))
  })
  
  app.Listen(":3000")
}

Test

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