Created
July 3, 2014 14:10
-
-
Save manucorporat/eb0cd3cb545caa4f8f5c to your computer and use it in GitHub Desktop.
fixed goroutine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/gin-gonic/gin" // at 30ea9c06fc9cac893f10d6ad0847a510cf35aeaf | |
"time" | |
) | |
func main() { | |
r := gin.NewWithConfig(gin.Config{ | |
CacheSize: 5, | |
Preallocated: 3, | |
}) | |
r.GET("", func(g *gin.Context) { | |
g.JSON(200, gin.H{"foo": "bar"}) | |
time.Sleep(100 * time.Millisecond) | |
}) | |
r.GET("/long", func(g *gin.Context) { | |
g.Keep() | |
go func() { | |
time.Sleep(20 * time.Second) | |
fmt.Printf("Url (only available via /long): %s\n", g.Req.URL.String()) | |
g.Release() | |
}() | |
g.JSON(200, gin.H{"foo": "bar"}) | |
}) | |
r.Run(":8082") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment