Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lil5/gin-url-rewrite
URL Rewrite middleware for gin
https://github.com/lil5/gin-url-rewrite
gin gin-gonic go golang middleware rewrite url
Last synced: 24 days ago
JSON representation
URL Rewrite middleware for gin
- Host: GitHub
- URL: https://github.com/lil5/gin-url-rewrite
- Owner: lil5
- License: wtfpl
- Created: 2021-11-25T13:57:27.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-11-25T14:11:04.000Z (about 3 years ago)
- Last Synced: 2024-11-15T22:52:43.153Z (about 1 month ago)
- Topics: gin, gin-gonic, go, golang, middleware, rewrite, url
- Language: Go
- Homepage:
- Size: 1000 Bytes
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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````go
package mainfunc 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](/gin-url-rewrite.go) in to your project.
## License
WTFPL – Do What the Fuck You Want to Public License