Fix #406, #407 and gofmt all examples

This commit is contained in:
Javier Provecho Fernandez 2015-08-17 12:49:28 +02:00
parent dba1781814
commit 02df324cc6

View File

@ -12,7 +12,7 @@ Gin is a web framework written in Golang. It features a martini-like API with mu
![Gin console logger](https://gin-gonic.github.io/gin/other/console.png) ![Gin console logger](https://gin-gonic.github.io/gin/other/console.png)
``` ```sh
$ cat test.go $ cat test.go
``` ```
```go ```go
@ -84,7 +84,7 @@ BenchmarkZeus_GithubAll | 2000 | 944234 | 300688 | 2648
1. Download and install it: 1. Download and install it:
```sh ```sh
go get github.com/gin-gonic/gin $ go get github.com/gin-gonic/gin
``` ```
2. Import it in your code: 2. Import it in your code:
@ -170,6 +170,7 @@ func main() {
c.JSON(200, gin.H{ c.JSON(200, gin.H{
"status": "posted", "status": "posted",
"message": message, "message": message,
"nick": nick,
}) })
}) })
router.Run(":8080") router.Run(":8080")
@ -195,7 +196,7 @@ func main() {
name := c.PostForm("name") name := c.PostForm("name")
message := c.PostForm("message") message := c.PostForm("message")
fmt.Print("id: %s; page: %s; name: %s; message: %s", id, page, name, message) fmt.Printf("id: %s; page: %s; name: %s; message: %s", id, page, name, message)
}) })
router.Run(":8080") router.Run(":8080")
} }
@ -367,7 +368,7 @@ func main() {
``` ```
Test it with: Test it with:
```bash ```sh
$ curl -v --form user=user --form password=password http://localhost:8080/login $ curl -v --form user=user --form password=password http://localhost:8080/login
``` ```
@ -439,7 +440,8 @@ func main() {
} }
``` ```
```html ```html
<html><h1> <html>
<h1>
{{ .title }} {{ .title }}
</h1> </h1>
</html> </html>
@ -559,17 +561,16 @@ func main() {
r.GET("/long_async", func(c *gin.Context) { r.GET("/long_async", func(c *gin.Context) {
// create copy to be used inside the goroutine // create copy to be used inside the goroutine
c_cp := c.Copy() cCp := c.Copy()
go func() { go func() {
// simulate a long task with time.Sleep(). 5 seconds // simulate a long task with time.Sleep(). 5 seconds
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
// note than you are using the copied context "c_cp", IMPORTANT // note than you are using the copied context "c_cp", IMPORTANT
log.Println("Done! in path " + c_cp.Request.URL.Path) log.Println("Done! in path " + cCp.Request.URL.Path)
}() }()
}) })
r.GET("/long_sync", func(c *gin.Context) { r.GET("/long_sync", func(c *gin.Context) {
// simulate a long task with time.Sleep(). 5 seconds // simulate a long task with time.Sleep(). 5 seconds
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)