URL Rewrite middleware for gin

Url Rewrite middleware for gin

Example

In this exable these urls use the same route

  • http://localhost:1234/test-me
  • http://localhost:1234/index.php/test-me

And

  • http://localhost:1234/v1/test-me
  • http://localhost:1234/v1.php/test-me
package main

func main() {
	r := gin.Default()
	r.Use(
      middleware.UrlRewrite(r, "/index.php", ""),
      middleware.UrlRewrite(r, "/v1.php", "/v1"),
   )

	r.GET("/test-me", func(c *gin.Context) {
		c.Status(http.StatusTeapot)
	})

   r.GET("/v1/test-me", func(c *gin.Context) {
		c.Status(http.StatusOK)
	})
	r.Run(":1234")
}

Install

copy the contents of gin-url-rewrite.go in to your project.

License

WTFPL – Do What the Fuck You Want to Public License

Similar Resources

Simple middleware to rate-limit HTTP requests.

Tollbooth This is a generic middleware to rate-limit HTTP requests. NOTE 1: This library is considered finished. NOTE 2: Major version changes are bac

Dec 28, 2022

OpenID Connect (OIDC) http middleware for Go

Go OpenID Connect (OIDC) HTTP Middleware Introduction This is a middleware for http to make it easy to use OpenID Connect. Currently Supported framewo

Jan 1, 2023

Go HTTP middleware to filter clients by IP

Go HTTP middleware to filter clients by IP

Oct 30, 2022

Chi ip banner is a chi middleware that bans some ips from your Chi http server.

Chi Ip Banner Chi ip banner is a chi middleware that bans some ips from your Chi http server. It reads a .txt file in your project's root, called bani

Jan 4, 2022

A customized middleware of DAPR.

A customized middleware of DAPR.

Dec 24, 2021

Fiber middleware for server-timing

Server Timing This is a Fiber middleware for the [W3C Server-Timing API] based on mitchellh/go-server-timing

Feb 6, 2022

gin panic 拦截中间件, 基于插件的实现方式, 同时多种自定义回调通知(企业微信,钉钉,邮件, ES, MongoDB, MySQL 等等方式)

gin panic 拦截中间件 编程中有效的实践 go 程序 panic 是什么 ❓ 程序 panic 主要程序异常,程序不能继续向下推进时向调用者抛出的一个异常的机制,如果用户没有执行错误拦截,那么程序会一直往上抛出错误信息, 直到用户拦截,亦或是没有拦截会打印输出错误信息, 然后 exit(2)

Jun 16, 2021

Gin-errorhandling - Gin Error Handling Middleware is a middleware for the popular Gin framework

Gin Error Handling Middleware Gin Error Handling Middleware is a middleware for

Sep 19, 2022

A high performance gin middleware to cache http response. Compared to gin-contrib/cache, It has a huge performance improvement. 高性能gin缓存中间件,相比于官方版本,有明显性能提升。

A high performance gin middleware to cache http response. Compared to gin-contrib/cache, It has a huge performance improvement. 高性能gin缓存中间件,相比于官方版本,有明显性能提升。

A high performance gin middleware to cache http response. Compared to gin-contrib/cache. It has a huge performance improvement.

Dec 28, 2022

Gin-cache - Gin cache middleware with golang

Gin-cache - Gin cache middleware with golang

Nov 28, 2022

:steam_locomotive: Decodes url.Values into Go value(s) and Encodes Go value(s) into url.Values. Dual Array and Full map support.

Package form Package form Decodes url.Values into Go value(s) and Encodes Go value(s) into url.Values. It has the following features: Supports map of

Dec 26, 2022

High-Performance Shortlink ( Short URL ) app creator in Golang. For privacy reasons, you may prefer to host your own short URL app and this is the one to use.

High-Performance Shortlink ( Short URL ) app creator in Golang. For privacy reasons, you may prefer to host your own short URL app and this is the one to use.

About The Project Shortlink App in Golang Multiple Node based Architecture to create and scale at ease Highly performant key-value storage system Cent

Jan 3, 2023

Go-based search engine URL collector , support Google, Bing, can be based on Google syntax batch collection URL

Go-based search engine URL collector , support Google, Bing, can be based on Google syntax batch collection URL

Go-based search engine URL collector , support Google, Bing, can be based on Google syntax batch collection URL

Nov 9, 2022

A productivity tools to diagnose list of exported URL status from Google Search Console, Analytics, Sitemap URL...etc.

google-url-checker A productivity tools to diagnose list of exported URL status from Google Search Console, Analytics, Sitemap URL...etc. A quick way

Dec 31, 2021

Putty-url-scheme - Open PuTTY as a url scheme

PuTTY URL Scheme Helper Open PuTTY as a url scheme Install download release bina

Apr 25, 2022

Test-app-url-shortner - A sample url shortener app to test Keploy integration capabilities

Test-app-url-shortner - A sample url shortener app to test Keploy integration capabilities

test-app-url-shortner A sample url shortener app to test Keploy integration capa

Jan 23, 2022

recover(4) go rewrite

This is a partial go rewrite of the original C version. Original C version authors: Gorka Guardiola, [email protected] Russ Cox, [email protected] Eric Va

Dec 19, 2022

Cli tool to relabel Prometheus TSDB block via Thanos rewrite

promrelabel Tool for easier relabeling prometheus TSDB block data. This cli tool does the same thing as thanos tools bucket rewrite --rewrite.to-relab

Sep 29, 2022

rewrite of logarthmic brightness adjustment tool

bright(ness) rewrite of this gist from this blog article (credit to @konradstrack) in go. Functionality, except the program won't fail if the display

Oct 15, 2021
Gin middleware for session.

wsession Gin middleware for session management with multi-backend support: cookie-based Redis memstore Usage Start using it Download and install it: g

Jan 9, 2022
Painless middleware chaining for Go

Alice Alice provides a convenient way to chain your HTTP middleware functions and the app handler. In short, it transforms Middleware1(Middleware2(Mid

Dec 26, 2022
Go http.Hander based middleware stack with context sharing

wrap Package wrap creates a fast and flexible middleware stack for http.Handlers. Features small; core is only 13 LOC based on http.Handler interface;

Apr 5, 2022
Minimalist net/http middleware for golang

interpose Interpose is a minimalist net/http middleware framework for golang. It uses http.Handler as its core unit of functionality, minimizing compl

Sep 27, 2022
Lightweight Middleware for net/http

MuxChain MuxChain is a small package designed to complement net/http for specifying chains of handlers. With it, you can succinctly compose layers of

Dec 10, 2022
Idiomatic HTTP Middleware for Golang

Negroni Notice: This is the library formerly known as github.com/codegangsta/negroni -- Github will automatically redirect requests to this repository

Jan 2, 2023
A tiny http middleware for Golang with added handlers for common needs.

rye A simple library to support http services. Currently, rye provides a middleware handler which can be used to chain http handlers together while pr

Jan 4, 2023
A Go middleware that stores various information about your web application (response time, status code count, etc.)

Go stats handler stats is a net/http handler in golang reporting various metrics about your web application. This middleware has been developed and re

Dec 10, 2022
gorilla/csrf provides Cross Site Request Forgery (CSRF) prevention middleware for Go web applications & services 🔒

gorilla/csrf gorilla/csrf is a HTTP middleware library that provides cross-site request forgery (CSRF) protection. It includes: The csrf.Protect middl

Jan 9, 2023
A collection of useful middleware for Go HTTP services & web applications 🛃

gorilla/handlers Package handlers is a collection of handlers (aka "HTTP middleware") for use with Go's net/http package (or any framework supporting

Dec 31, 2022