参考了这篇帖子:

https://golangtc.com/t/570b403eb09ecc66b90002d9

golang web如何发送小包的chunked数据

以下是代码:

	r.GET("/test_stream", func(c *gin.Context){
w := c.Writer
header := w.Header()
header.Set("Transfer-Encoding", "chunked")
header.Set("Content-Type", "text/html")
w.WriteHeader(http.StatusOK)
w.Write([]byte(`
<html>
<body>
`))
w.(http.Flusher).Flush()
for i:=0 ;i<10; i++{
w.Write([]byte(fmt.Sprintf(`
<h1>%d</h1>
`,i)))
w.(http.Flusher).Flush()
time.Sleep(time.Duration(1) * time.Second)
}
w.Write([]byte(` </body>
</html>
`))
w.(http.Flusher).Flush()
})

最新文章

  1. 【干货分享】流程DEMO-制度发文和干部任免
  2. web应用程序
  3. JQuery 筛选器
  4. 半平面交模板(BZOJ1007)
  5. Sprint第二个冲刺(第五天)
  6. 1. redis简介
  7. AcmeAir安装AI探针--SaaS版
  8. Memcached 缓存个体,对象,泛型,表
  9. Redis持久存储-AOF&RDB
  10. 聊聊RocksDB Compact
  11. Linux编程 18 安装软件程序(yum工具对软件包安装,删除,更新介绍)
  12. loadrunner&#160;场景设计-手工场景设计
  13. String系列-----AbstractStringBuilder
  14. callback源码分析——callbacks
  15. python 首次安装 报错
  16. nginx:在linux上进行nginx的安装
  17. 企点微服务网关演进之路 IT大咖说 - 大咖干货,不再错过
  18. openstack neutron中涉及的网络设备
  19. ida不错的插件记录
  20. 日记整理----&gt;2016-11-01

热门文章

  1. [C# Expression] 之基础概念
  2. 【LeetCode】1056. Confusing Number 解题报告(C++)
  3. 【LeetCode】115. Distinct Subsequences 解题报告(Python)
  4. 【LeetCode】753. Cracking the Safe 解题报告(Python)
  5. 【LeetCode】414. Third Maximum Number 解题报告(Python & C++)
  6. 【LeetCode】905. Sort Array By Parity 解题报告(Python)
  7. hdu-5569matrix(dp)
  8. codeforce-424C. Magic Formulas(数学)
  9. SOA 和微服务
  10. [object_detect]使用MobileNetSSD进行对象检测