From 6fa85864edb1680633342759b5f536e21d3a79c1 Mon Sep 17 00:00:00 2001 From: mopemoepe Date: Tue, 8 Jul 2014 15:53:10 +0900 Subject: [PATCH 1/7] Manage Dependencies With Godep --- Godeps/Godeps.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Godeps/Godeps.json diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json new file mode 100644 index 00000000..a224fcd3 --- /dev/null +++ b/Godeps/Godeps.json @@ -0,0 +1,10 @@ +{ + "ImportPath": "github.com/gin-gonic/gin", + "GoVersion": "devel +2699961d1143 Wed Jun 25 09:57:48 2014 -0400", + "Deps": [ + { + "ImportPath": "github.com/julienschmidt/httprouter", + "Rev": "7deadb6844d2c6ff1dfb812eaa439b87cdaedf20" + } + ] +} From fadb06968fec7462f4c2ecfa74e6a1b2509470d8 Mon Sep 17 00:00:00 2001 From: mopemoepe Date: Tue, 8 Jul 2014 17:53:55 +0900 Subject: [PATCH 2/7] Fix go version --- Godeps/Godeps.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index a224fcd3..d963b7ea 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -1,6 +1,6 @@ { "ImportPath": "github.com/gin-gonic/gin", - "GoVersion": "devel +2699961d1143 Wed Jun 25 09:57:48 2014 -0400", + "GoVersion": "go1.3", "Deps": [ { "ImportPath": "github.com/julienschmidt/httprouter", From cfb3ce5aac1934640d0854264c3f5f05a57dbe27 Mon Sep 17 00:00:00 2001 From: mopemoepe Date: Tue, 8 Jul 2014 18:41:12 +0900 Subject: [PATCH 3/7] Ingnore godep workspace --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..08e84966 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +Godeps/* +!Godep.json From 6c8c90115d513f4b008f04dcc9aae4c8ffe0bff3 Mon Sep 17 00:00:00 2001 From: Javier Provecho Date: Tue, 8 Jul 2014 11:55:20 +0200 Subject: [PATCH 4/7] Update README.md Example of Catch-All parameters. --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index acba80f3..63c67e84 100644 --- a/README.md +++ b/README.md @@ -84,20 +84,22 @@ func main() { ```go func main() { r := gin.Default() - + + // This handler will match /user/john but will not match neither /user/ or /user r.GET("/user/:name", func(c *gin.Context) { name := c.Params.ByName("name") message := "Hello "+name c.String(200, message) }) - r.GET("/user/:name/:action", func(c *gin.Context) { + // However, this one will match /user/john and also /user/john/send + r.GET("/user/:name/*action", func(c *gin.Context) { name := c.Params.ByName("name") action := c.Params.ByName("action") message := name + " is " + action c.String(200, message) }) - + // Listen and server on 0.0.0.0:8080 r.Run(":8080") } From c224bf82111883dbe354edf9376642f615b7248e Mon Sep 17 00:00:00 2001 From: Javier Provecho Date: Tue, 8 Jul 2014 12:20:05 +0200 Subject: [PATCH 5/7] Update .gitignore Fixed PR #56. --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 08e84966..96c135f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ Godeps/* -!Godep.json +!Godeps/Godeps.json From 9880758ddbc807d38625b4d9fbbb88cea8575325 Mon Sep 17 00:00:00 2001 From: Dmitry Sedykh Date: Tue, 8 Jul 2014 16:07:59 +0400 Subject: [PATCH 6/7] No repeat call c.Writer.Status() --- logger.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logger.go b/logger.go index da35ffb7..5c018a4a 100644 --- a/logger.go +++ b/logger.go @@ -69,7 +69,7 @@ func Logger() HandlerFunc { latency := end.Sub(start) stdlogger.Printf("[GIN] %v |%s %3d %s| %12v | %s %4s %s\n", end.Format("2006/01/02 - 15:04:05"), - color, c.Writer.Status(), reset, + color, code, reset, latency, requester, c.Req.Method, c.Req.URL.Path, From a235e0fb32df61edfa9859548c18ca925487cd7f Mon Sep 17 00:00:00 2001 From: Dmitry Sedykh Date: Tue, 8 Jul 2014 16:10:27 +0400 Subject: [PATCH 7/7] Add HTML POST Form support in Bind --- gin.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/gin.go b/gin.go index a06c13a5..55fa8339 100644 --- a/gin.go +++ b/gin.go @@ -17,12 +17,13 @@ import ( ) const ( - AbortIndex = math.MaxInt8 / 2 - MIMEJSON = "application/json" - MIMEHTML = "text/html" - MIMEXML = "application/xml" - MIMEXML2 = "text/xml" - MIMEPlain = "text/plain" + AbortIndex = math.MaxInt8 / 2 + MIMEJSON = "application/json" + MIMEHTML = "text/html" + MIMEXML = "application/xml" + MIMEXML2 = "text/xml" + MIMEPlain = "text/plain" + MIMEPOSTForm = "application/x-www-form-urlencoded" ) const ( @@ -407,7 +408,7 @@ func (c *Context) Bind(obj interface{}) bool { var b binding.Binding ctype := filterFlags(c.Req.Header.Get("Content-Type")) switch { - case c.Req.Method == "GET": + case c.Req.Method == "GET" || ctype == MIMEPOSTForm: b = binding.Form case ctype == MIMEJSON: b = binding.JSON