From 6d92063b996e0d5e849d78a38927a9c5b85e8e75 Mon Sep 17 00:00:00 2001 From: Javier Provecho Fernandez Date: Thu, 1 Jan 2015 16:22:02 +0100 Subject: [PATCH 1/6] Fix unexported field detection --- binding/binding.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binding/binding.go b/binding/binding.go index 72b23dfc..20d6bdc2 100644 --- a/binding/binding.go +++ b/binding/binding.go @@ -170,7 +170,7 @@ func Validate(obj interface{}) error { field := typ.Field(i) // Allow ignored and unexported fields in the struct - if field.Tag.Get("form") == "-" || field.PkgPath != "" { + if len(field.PkgPath) > 0 || field.Tag.Get("form") == "-" { continue } From b69dde8e68d5331f1f6dcd759e6bbbbae47644b8 Mon Sep 17 00:00:00 2001 From: Ignacio Galindo Date: Thu, 29 Jan 2015 20:14:09 -0600 Subject: [PATCH 2/6] Specify utf-8 as content type charset on renderers --- context_test.go | 12 ++++++------ render/render.go | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/context_test.go b/context_test.go index 8435ac56..1804c162 100644 --- a/context_test.go +++ b/context_test.go @@ -76,7 +76,7 @@ func TestContextJSON(t *testing.T) { t.Errorf("Response should be {\"foo\":\"bar\"}, was: %s", w.Body.String()) } - if w.HeaderMap.Get("Content-Type") != "application/json" { + if w.HeaderMap.Get("Content-Type") != "application/json; charset=utf-8" { t.Errorf("Content-Type should be application/json, was %s", w.HeaderMap.Get("Content-Type")) } } @@ -103,7 +103,7 @@ func TestContextHTML(t *testing.T) { t.Errorf("Response should be Hello alexandernyquist, was: %s", w.Body.String()) } - if w.HeaderMap.Get("Content-Type") != "text/html" { + if w.HeaderMap.Get("Content-Type") != "text/html; charset=utf-8" { t.Errorf("Content-Type should be text/html, was %s", w.HeaderMap.Get("Content-Type")) } } @@ -125,7 +125,7 @@ func TestContextString(t *testing.T) { t.Errorf("Response should be test, was: %s", w.Body.String()) } - if w.HeaderMap.Get("Content-Type") != "text/plain" { + if w.HeaderMap.Get("Content-Type") != "text/plain; charset=utf-8" { t.Errorf("Content-Type should be text/plain, was %s", w.HeaderMap.Get("Content-Type")) } } @@ -147,7 +147,7 @@ func TestContextXML(t *testing.T) { t.Errorf("Response should be bar, was: %s", w.Body.String()) } - if w.HeaderMap.Get("Content-Type") != "application/xml" { + if w.HeaderMap.Get("Content-Type") != "application/xml; charset=utf-8" { t.Errorf("Content-Type should be application/xml, was %s", w.HeaderMap.Get("Content-Type")) } } @@ -336,7 +336,7 @@ func TestBindingJSON(t *testing.T) { t.Errorf("Response should be {\"parsed\":\"bar\"}, was: %s", w.Body.String()) } - if w.HeaderMap.Get("Content-Type") != "application/json" { + if w.HeaderMap.Get("Content-Type") != "application/json; charset=utf-8" { t.Errorf("Content-Type should be application/json, was %s", w.HeaderMap.Get("Content-Type")) } } @@ -369,7 +369,7 @@ func TestBindingJSONEncoding(t *testing.T) { t.Errorf("Response should be {\"parsed\":\"嘉\"}, was: %s", w.Body.String()) } - if w.HeaderMap.Get("Content-Type") != "application/json" { + if w.HeaderMap.Get("Content-Type") != "application/json; charset=utf-8" { t.Errorf("Content-Type should be application/json, was %s", w.HeaderMap.Get("Content-Type")) } } diff --git a/render/render.go b/render/render.go index a81fffe9..467a3299 100644 --- a/render/render.go +++ b/render/render.go @@ -50,7 +50,7 @@ var ( ) func writeHeader(w http.ResponseWriter, code int, contentType string) { - w.Header().Set("Content-Type", contentType) + w.Header().Set("Content-Type", contentType+"; charset=utf-8") w.WriteHeader(code) } From d2c369995722ee93b380f80f23cacbb7ac38d2e3 Mon Sep 17 00:00:00 2001 From: "SRK.Lyu" Date: Sat, 31 Jan 2015 20:09:44 +0800 Subject: [PATCH 3/6] Update httprouter version and edit readme about the named parameters --- Godeps/Godeps.json | 2 +- README.md | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 905a487f..2d43fc9f 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -4,7 +4,7 @@ "Deps": [ { "ImportPath": "github.com/julienschmidt/httprouter", - "Rev": "90d58bada7e6154006f2728ee09053271154a8f6" + "Rev": "00ce1c6a267162792c367acc43b1681a884e1872" } ] } diff --git a/README.md b/README.md index b49c9b01..f1ac5fb1 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,8 @@ func main() { c.String(200, message) }) - // However, this one will match /user/john and also /user/john/send + // However, this one will match /user/john/ and also /user/john/send + // If no other routers match /user/john, it will redirect to /user/join/ r.GET("/user/:name/*action", func(c *gin.Context) { name := c.Params.ByName("name") action := c.Params.ByName("action") From 713068594c7c6b6810755c16f91f78c265a07dae Mon Sep 17 00:00:00 2001 From: Javier Provecho Fernandez Date: Wed, 4 Feb 2015 23:00:51 +0100 Subject: [PATCH 4/6] Update README.md - Reorganize roadmap for v1.0, done in the bottom, to do at top. - Added request for #155, swagger support. --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ce3ea7ab..df1ed211 100644 --- a/README.md +++ b/README.md @@ -35,24 +35,25 @@ func main() { ##Gin is new, will it be supported? -Yes, Gin is an internal project of [my](https://github.com/manucorporat) upcoming startup. We developed it and we are going to continue using and improve it. +Yes, Gin is an internal tool of [Manu](https://github.com/manucorporat) and [Javi](https://github.com/javierprovecho) for many of our projects/start-ups. We developed it and we are going to continue using and improve it. ##Roadmap for v1.0 -- [x] Performance improments, reduce allocation and garbage collection overhead -- [x] Fix bugs -- [ ] Stable API - [ ] Ask our designer for a cool logo - [ ] Add tons of unit tests - [ ] Add internal benchmarks suite +- [ ] More powerful validation API +- [ ] Improve documentation +- [ ] Add Swagger support +- [x] Stable API - [x] Improve logging system - [x] Improve JSON/XML validation using bindings - [x] Improve XML support - [x] Flexible rendering system -- [ ] More powerful validation API -- [ ] Improve documentation -- [ ] Add more cool middlewares, for example redis caching (this also helps developers to understand the framework). +- [x] Add more cool middlewares, for example redis caching (this also helps developers to understand the framework). - [x] Continuous integration +- [x] Performance improments, reduce allocation and garbage collection overhead +- [x] Fix bugs From 44f024a413c9afc57970740a5fe3b6b6597bfe75 Mon Sep 17 00:00:00 2001 From: Klemen Sever Date: Thu, 5 Feb 2015 15:24:22 +0100 Subject: [PATCH 5/6] Fixd newline problem with debugPrint in Run* functions --- gin.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gin.go b/gin.go index 37e6e4dd..42c4b1f6 100644 --- a/gin.go +++ b/gin.go @@ -127,7 +127,7 @@ func (engine *Engine) ServeHTTP(writer http.ResponseWriter, request *http.Reques } func (engine *Engine) Run(addr string) error { - debugPrint("Listening and serving HTTP on %s", addr) + debugPrint("Listening and serving HTTP on %s\n", addr) if err := http.ListenAndServe(addr, engine); err != nil { return err } @@ -135,7 +135,7 @@ func (engine *Engine) Run(addr string) error { } func (engine *Engine) RunTLS(addr string, cert string, key string) error { - debugPrint("Listening and serving HTTPS on %s", addr) + debugPrint("Listening and serving HTTPS on %s\n", addr) if err := http.ListenAndServeTLS(addr, cert, key, engine); err != nil { return err } From 651305c0f5cd1ee9fd67b9629f15a323b7173b68 Mon Sep 17 00:00:00 2001 From: Robert Wilkinson Date: Fri, 6 Feb 2015 09:14:12 -0800 Subject: [PATCH 6/6] Update README.md --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index df1ed211..a28d9850 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,25 @@ func main() { r.Run(":8080") } ``` +###Form parameters +```go +func main() { + r := gin.Default() + + // This will respond to urls like search?firstname=Jane&lastname=Doe + r.GET("/search", func(c *gin.Context) { + // You need to call ParseForm() on the request to receive url and form params first + c.Request.ParseForm() + + firstname := c.Request.Form.Get("firstname") + lastname := c.Request.Form.get("lastname") + message := "Hello "+ firstname + lastname + c.String(200, message) + }) + r.Run(":8080") +} +``` #### Grouping routes ```go