1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| package main
import ( "log" "time"
"github.com/gin-gonic/gin" )
func main() { r := gin.Default() r.GET("/long_async", func(c *gin.Context) { copyContext := c.Copy() go func() { time.Sleep(3 * time.Second) log.Println("异步执行:" + copyContext.Request.URL.Path) }() }) r.GET("/long_sync", func(c *gin.Context) { time.Sleep(3 * time.Second) log.Println("同步执行:" + c.Request.URL.Path) })
r.Run(":8000") }
|