diff --git a/AUTHORS.md b/AUTHORS.md index accf8b03..45c54387 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -9,6 +9,10 @@ List of all the awesome people working to make Gin the best Web Framework in Go. People and companies, who have contributed, in alphabetical order. +**@achedeuzot (Klemen Sever)** +- Fix newline debug printing + + **@adammck (Adam Mckaig)** - Add MIT license @@ -60,7 +64,7 @@ People and companies, who have contributed, in alphabetical order. - Fix typo. SetHTTPTemplate -> SetHTMLTemplate -**@jammie-stackhouse (Jamie Stackhouse) +**@jammie-stackhouse (Jamie Stackhouse)** - Add more shortcuts for router methods @@ -72,6 +76,10 @@ People and companies, who have contributed, in alphabetical order. - Fix typo in comment +**@joiggama (Ignacio Galindo)** +- Add utf-8 charset header on renders + + **@julienschmidt (Julien Schmidt)** - gofmt the code examples @@ -130,6 +138,10 @@ People and companies, who have contributed, in alphabetical order. - Fix Port usage in README. +**@RobAWilkinson (Robert Wilkinson)** +- Add example of forms and params + + **@se77en (Damon Zhao)** - Improve color logging @@ -142,7 +154,7 @@ People and companies, who have contributed, in alphabetical order. - Fixes some texts in README II -**@slimmy (Jimmy Pettersson) +**@slimmy (Jimmy Pettersson)** - Added messages for required bindings @@ -150,6 +162,10 @@ People and companies, who have contributed, in alphabetical order. - Add support for ignored/unexported fields in binding +**@superalsrk (SRK.Lyu)** +- Update httprouter godeps + + **@yosssi (Keiji Yoshida)** - Fix link in README diff --git a/CHANGELOG.md b/CHANGELOG.md index 461ea024..72c848b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ #Changelog -###Gin 0.5 (Jan 4, 2015) +###Gin 0.6 (Mar 7, 2015) + + +###Gin 0.5 (Feb 7, 2015) - [NEW] Content Negotiation - [FIX] Solved security bug that allow a client to spoof ip diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 20da1fcf..2d43fc9f 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -4,7 +4,7 @@ "Deps": [ { "ImportPath": "github.com/julienschmidt/httprouter", - "Rev": "aeec11926f7a8fab580383810e1b1bbba99bdaa7" + "Rev": "00ce1c6a267162792c367acc43b1681a884e1872" } ] } diff --git a/README.md b/README.md index d38ca932..3c6ca7ee 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,4 @@ -#Gin Web Framework - -[![GoDoc](https://godoc.org/github.com/gin-gonic/gin?status.svg)](https://godoc.org/github.com/gin-gonic/gin) -[![Build Status](https://travis-ci.org/gin-gonic/gin.svg)](https://travis-ci.org/gin-gonic/gin) +#Gin Web Framework [![GoDoc](https://godoc.org/github.com/gin-gonic/gin?status.svg)](https://godoc.org/github.com/gin-gonic/gin) [![Build Status](https://travis-ci.org/gin-gonic/gin.svg)](https://travis-ci.org/gin-gonic/gin) Gin is a web framework written in Golang. It features a martini-like API with much better performance, up to 40 times faster thanks to [httprouter](https://github.com/julienschmidt/httprouter). If you need performance and good productivity, you will love Gin. @@ -35,24 +32,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 -- [X] 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 @@ -133,7 +131,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") @@ -145,7 +144,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 @@ -329,22 +346,6 @@ func main() { Note: this will use `httpNotFound` instead of the Router's `NotFound` handler. -####Serving static files - -Use Engine.ServeFiles(path string, root http.FileSystem): - -```go -func main() { - r := gin.Default() - r.Static("/assets", "./assets") - - // Listen and server on 0.0.0.0:8080 - r.Run(":8080") -} -``` - -Note: this will use `httpNotFound` instead of the Router's `NotFound` handler. - ####HTML rendering Using LoadHTMLTemplates() diff --git a/binding/binding.go b/binding/binding.go index 92460a55..99f3d0e1 100644 --- a/binding/binding.go +++ b/binding/binding.go @@ -170,7 +170,7 @@ func Validate(obj interface{}, parents ...string) 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 } diff --git a/context_test.go b/context_test.go index 851a56c5..c77cd279 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/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 } 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) }