Skip to content

Instantly share code, notes, and snippets.

@manucorporat
Created July 3, 2014 14:10
Show Gist options
  • Save manucorporat/eb0cd3cb545caa4f8f5c to your computer and use it in GitHub Desktop.
Save manucorporat/eb0cd3cb545caa4f8f5c to your computer and use it in GitHub Desktop.
fixed goroutine
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