Fenny / rewrite

🧬 Rewrite middleware for Fiber

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rewrite

Release Discord Test Security Linter

Install

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

Example

package main

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

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) {
    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

🧬 Rewrite middleware for Fiber

https://github.com/gofiber/fiber

License:MIT License


Languages

Language:Go 100.0%