parent
dba1781814
commit
02df324cc6
19
README.md
19
README.md
@ -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)
|
||||
|
||||
```
|
||||
```sh
|
||||
$ cat test.go
|
||||
```
|
||||
```go
|
||||
@ -84,7 +84,7 @@ BenchmarkZeus_GithubAll | 2000 | 944234 | 300688 | 2648
|
||||
1. Download and install it:
|
||||
|
||||
```sh
|
||||
go get github.com/gin-gonic/gin
|
||||
$ go get github.com/gin-gonic/gin
|
||||
```
|
||||
2. Import it in your code:
|
||||
|
||||
@ -170,6 +170,7 @@ func main() {
|
||||
c.JSON(200, gin.H{
|
||||
"status": "posted",
|
||||
"message": message,
|
||||
"nick": nick,
|
||||
})
|
||||
})
|
||||
router.Run(":8080")
|
||||
@ -195,7 +196,7 @@ func main() {
|
||||
name := c.PostForm("name")
|
||||
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")
|
||||
}
|
||||
@ -367,7 +368,7 @@ func main() {
|
||||
```
|
||||
|
||||
Test it with:
|
||||
```bash
|
||||
```sh
|
||||
$ curl -v --form user=user --form password=password http://localhost:8080/login
|
||||
```
|
||||
|
||||
@ -439,9 +440,10 @@ func main() {
|
||||
}
|
||||
```
|
||||
```html
|
||||
<html><h1>
|
||||
<html>
|
||||
<h1>
|
||||
{{ .title }}
|
||||
</h1>
|
||||
</h1>
|
||||
</html>
|
||||
```
|
||||
|
||||
@ -559,17 +561,16 @@ func main() {
|
||||
|
||||
r.GET("/long_async", func(c *gin.Context) {
|
||||
// create copy to be used inside the goroutine
|
||||
c_cp := c.Copy()
|
||||
cCp := c.Copy()
|
||||
go func() {
|
||||
// simulate a long task with time.Sleep(). 5 seconds
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
// 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) {
|
||||
// simulate a long task with time.Sleep(). 5 seconds
|
||||
time.Sleep(5 * time.Second)
|
||||
|
Loading…
Reference in New Issue
Block a user