From a660a6eb6e776060f85b4d0edd5edee72ffe49c7 Mon Sep 17 00:00:00 2001 From: Skuli Oskarsson Date: Mon, 30 Jun 2014 22:58:45 +0000 Subject: [PATCH 01/10] Fixed some more code in the readme file There were some more errors in the code snippets --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ed6467d..cf006e9 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ import "github.com/gin-gonic/gin" func main() { r := gin.Default() - r.GET("ping", func(c *gin.Context){ + r.GET("/ping", func(c *gin.Context){ c.String(200, "pong") }) @@ -207,7 +207,7 @@ Using LoadHTMLTemplates() func main() { r := gin.Default() r.LoadHTMLTemplates("templates/*") - r.GET("index", func(c *gin.Context) { + r.GET("/index", func(c *gin.Context) { obj := gin.H{"title": "Main website"} c.HTML(200, "index.tmpl", obj) }) @@ -250,7 +250,7 @@ func main() { r := gin.New() r.Use(Logger()) - r.GET("test", func(c *gin.Context){ + r.GET("/test", func(c *gin.Context){ example := r.Get("example").(string) // it would print: "12345" From 14077b10207d20db92df37ce08b9e384459d8cec Mon Sep 17 00:00:00 2001 From: Rajiv Kilaparti Date: Tue, 1 Jul 2014 11:37:13 +0530 Subject: [PATCH 02/10] Fix Port usage * Update Server's Listening Port from 8081 ==> 8080 --- examples/example_basic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/example_basic.go b/examples/example_basic.go index 575bd89..ea34343 100644 --- a/examples/example_basic.go +++ b/examples/example_basic.go @@ -51,5 +51,5 @@ func main() { }) // Listen and Server in 0.0.0.0:8080 - r.Run(":8081") + r.Run(":8080") } From 00bb3e2478e7e5a4cfb37b62b4be5880187706ac Mon Sep 17 00:00:00 2001 From: Alexander Nyquist Date: Tue, 1 Jul 2014 09:22:39 +0200 Subject: [PATCH 03/10] Setting response headers before calling WriteHeader. --- gin.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gin.go b/gin.go index fc5da8c..6344e68 100644 --- a/gin.go +++ b/gin.go @@ -300,10 +300,10 @@ func (c *Context) ParseBody(item interface{}) error { // Serializes the given struct as a JSON into the response body in a fast and efficient way. // It also sets the Content-Type as "application/json" func (c *Context) JSON(code int, obj interface{}) { + c.Writer.Header().Set("Content-Type", "application/json") if code >= 0 { c.Writer.WriteHeader(code) } - c.Writer.Header().Set("Content-Type", "application/json") encoder := json.NewEncoder(c.Writer) if err := encoder.Encode(obj); err != nil { c.Error(err, obj) @@ -314,10 +314,10 @@ func (c *Context) JSON(code int, obj interface{}) { // Serializes the given struct as a XML into the response body in a fast and efficient way. // It also sets the Content-Type as "application/xml" func (c *Context) XML(code int, obj interface{}) { + c.Writer.Header().Set("Content-Type", "application/xml") if code >= 0 { c.Writer.WriteHeader(code) } - c.Writer.Header().Set("Content-Type", "application/xml") encoder := xml.NewEncoder(c.Writer) if err := encoder.Encode(obj); err != nil { c.Error(err, obj) @@ -329,10 +329,10 @@ func (c *Context) XML(code int, obj interface{}) { // It also update the HTTP code and sets the Content-Type as "text/html". // See http://golang.org/doc/articles/wiki/ func (c *Context) HTML(code int, name string, data interface{}) { + c.Writer.Header().Set("Content-Type", "text/html") if code >= 0 { c.Writer.WriteHeader(code) } - c.Writer.Header().Set("Content-Type", "text/html") if err := c.engine.HTMLTemplates.ExecuteTemplate(c.Writer, name, data); err != nil { c.Error(err, map[string]interface{}{ "name": name, From 120b41fe1d4ae6b7c3ab57841778384df008dbf4 Mon Sep 17 00:00:00 2001 From: Jun Kimura Date: Wed, 2 Jul 2014 15:24:55 +0900 Subject: [PATCH 04/10] Fixes code examples in README --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 35f8962..4801c27 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,9 @@ func main() { message := "Hello "+name c.String(200, message) }) + + // Listen and server on 0.0.0.0:8080 + r.Run(":8080") } ``` @@ -167,6 +170,9 @@ func main() { } } }) + + // Listen and server on 0.0.0.0:8080 + r.Run(":8080") } ``` @@ -195,6 +201,9 @@ func main() { r.GET("/someXML", func(c *gin.Context) { c.XML(200, gin.H{"message": "hey", "status": 200}) }) + + // Listen and server on 0.0.0.0:8080 + r.Run(":8080") } ``` @@ -211,6 +220,9 @@ func main() { obj := gin.H{"title": "Main website"} c.HTML(200, "index.tmpl", obj) }) + + // Listen and server on 0.0.0.0:8080 + r.Run(":8080") } ``` @@ -222,6 +234,9 @@ func main() { r := gin.Default() html := template.ParseFiles("file1", "file2") r.HTMLTemplates = html + + // Listen and server on 0.0.0.0:8080 + r.Run(":8080") } ``` @@ -256,6 +271,9 @@ func main() { // it would print: "12345" log.Println(example) }) + + // Listen and server on 0.0.0.0:8080 + r.Run(":8080") } ``` From 9ea9e0fd5178d0e28d79ca2f594e1cb1fb962e9f Mon Sep 17 00:00:00 2001 From: Javier Provecho Date: Wed, 2 Jul 2014 11:47:55 +0200 Subject: [PATCH 05/10] Fix JSON Struct example --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index baebc79..1239620 100644 --- a/README.md +++ b/README.md @@ -190,12 +190,15 @@ func main() { r.GET("/moreJSON", func(c *gin.Context) { // You also can use a struct var msg struct { + Name string Message string - Status int + Number int } + msg.Name = "Lena" msg.Message = "hey" - msg.Status = 200 - c.JSON(200, msg.Status) + msg.Number = 123 + // Will output : {"Name": "Lena", "Message": "hey", "Number": 123} + c.JSON(200, msg) }) r.GET("/someXML", func(c *gin.Context) { From 406a509fa3626fa6f20c7a6e73699ef15a22facd Mon Sep 17 00:00:00 2001 From: Javier Provecho Date: Wed, 2 Jul 2014 11:53:45 +0200 Subject: [PATCH 06/10] Extra example --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1239620..8a051d0 100644 --- a/README.md +++ b/README.md @@ -190,14 +190,15 @@ func main() { r.GET("/moreJSON", func(c *gin.Context) { // You also can use a struct var msg struct { - Name string + Name string `json:"user"` Message string Number int } msg.Name = "Lena" msg.Message = "hey" msg.Number = 123 - // Will output : {"Name": "Lena", "Message": "hey", "Number": 123} + // Note that msg.Name becomes "user" in the JSON + // Will output : {"user": "Lena", "Message": "hey", "Number": 123} c.JSON(200, msg) }) From 0f32b5510010e9ef90a6df81816c2da95288a51c Mon Sep 17 00:00:00 2001 From: Javier Provecho Date: Wed, 2 Jul 2014 14:36:23 +0200 Subject: [PATCH 07/10] Add GoDoc Badge --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 8a051d0..744f380 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ #Gin Web Framework + +[![GoDoc]https://godoc.org/github.com/gin-gonic/gin?status.png)](https://godoc.org/github.com/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. If you need performance and good productivity, you will love Gin. [Check out the official web site](http://gin-gonic.github.io/gin/) From 0318ebab19450bb0411b11046dbd5a7e605a883f Mon Sep 17 00:00:00 2001 From: Javier Provecho Date: Wed, 2 Jul 2014 14:37:18 +0200 Subject: [PATCH 08/10] Fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 744f380..3c2fe1a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ #Gin Web Framework -[![GoDoc]https://godoc.org/github.com/gin-gonic/gin?status.png)](https://godoc.org/github.com/gin-gonic/gin) +[![GoDoc](https://godoc.org/github.com/golang/gddo?status.png)](http://godoc.org/github.com/golang/gddo) Gin is a web framework written in Golang. It features a martini-like API with much better performance, up to 40 times faster. If you need performance and good productivity, you will love Gin. [Check out the official web site](http://gin-gonic.github.io/gin/) From 15adea718dac7246343a25445ea05291aa7b8f6d Mon Sep 17 00:00:00 2001 From: Javier Provecho Date: Wed, 2 Jul 2014 14:38:01 +0200 Subject: [PATCH 09/10] Fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3c2fe1a..07e3bd0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ #Gin Web Framework -[![GoDoc](https://godoc.org/github.com/golang/gddo?status.png)](http://godoc.org/github.com/golang/gddo) +[![GoDoc](https://godoc.org/github.com/gin-gonic/gin?status.png)](https://godoc.org/github.com/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. If you need performance and good productivity, you will love Gin. [Check out the official web site](http://gin-gonic.github.io/gin/) From 728e1039248daecef07029599c0892518e1781a6 Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 3 Jul 2014 00:00:41 +0800 Subject: [PATCH 10/10] Fix README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 07e3bd0..850ee12 100644 --- a/README.md +++ b/README.md @@ -253,7 +253,7 @@ func main() { ```go func Logger() gin.HandlerFunc { return func(c *gin.Context) { - t : time.Now() + t := time.Now() // Set example variable c.Set("example", "12345")