M. Efe Çetin a458bd344c
v3 (feature): convert fiber.Ctx type to interface (#1928)
*  v3: convert fiber.Ctx type to interface

* update ctx methods

* add new methods to customize ctx, fix some problems

* update comments.

* fix something
2022-07-13 07:48:29 +02:00
..

Rewrite

Release Discord Test Security Linter

Install

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

Example

package main

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

func main() {
  app := fiber.New()
  
  app.Use(rewrite.New(rewrite.Config{
    Rules: map[string]string{
      "/old":   "/new",
      "/old/*": "/new/$1",
    },
  }))
  
  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