bu / gin-method-override Goto Github PK
View Code? Open in Web Editor NEWMethodOverride middleware for Gin web framework
License: MIT License
MethodOverride middleware for Gin web framework
License: MIT License
When I added this, it works, but it seems to run the method twice according to the logs (and database) :)
I slightly modified from your example in README.md:
main.go
:
package main
import (
method "github.com/bu/gin-method-override"
gin "github.com/gin-gonic/gin"
)
func main() {
// create a Gin engine
r := gin.Default()
r.LoadHTMLFiles("form.html")
// our middle-ware
r.Use(method.ProcessMethodOverride(r))
// routes
r.PUT("/test", func(c *gin.Context) {
c.String(200, "1")
})
r.GET("/", func(c *gin.Context) {
c.HTML(200, "form.html", gin.H{})
})
// listen to request
r.Run(":8080")
}
form.html
: (same as example)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<form action="/test" method="POST"> <!-- form method rewrite only works with POST request -->
<input type="hidden" name="_method" value="PUT">
<input type="text" name="testing" value="1">
<button type="submit">Send</button>
</form>
</body>
</html>
The output is: 11
instead of the expected 1
and I also see the line twice in the logs:
$ go run main.go
[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
- using env: export GIN_MODE=release
- using code: gin.SetMode(gin.ReleaseMode)
[GIN-debug] PUT /test --> main.main.func1 (4 handlers)
[GIN-debug] GET / --> main.main.func2 (4 handlers)
[GIN-debug] Listening and serving HTTP on :8080
[GIN] 2021/01/06 - 21:12:36 | 200 | 285.465µs | ::1 | GET "/"
[GIN] 2021/01/06 - 21:12:45 | 200 | 5.609µs | ::1 | PUT "/test"
[GIN] 2021/01/06 - 21:12:45 | 200 | 70.195µs | ::1 | PUT "/test"
Currently, this middleware will print two different records for single re-dispatch request.
Thanks for Tommy reporting this issue, related to #1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.