当前位置:网站首页>GoFrame缓冲输出到客户端Flush()
GoFrame缓冲输出到客户端Flush()
2022-08-09 16:10:00 【传说中胖子】
版本:v2.x
官方文档中介绍任何时候可以通过OutputBuffer方法输出缓冲区数据到客户端,并清空缓冲区数据。但使用r.Response.Flush()发现并不能实时输出。
修改下net\ghttp\ghttp_response_writer.go文件的Flush方法
if w.buffer.Len() > 0 {
w.writer.Write(w.buffer.Bytes())
w.writer.(http.Flusher).Flush() //添加此行
w.buffer.Reset()
}
以下为使用net/http原生写法
package main
import (
"fmt"
"log"
"net/http"
"time"
)
func handler(res http.ResponseWriter, r *http.Request) {
fmt.Fprintln(res, "<body>") //不加body没有效果
for i := 0; i < 10; i++ {
//fmt.Fprint(res, "<script>document.body.innerHTML = ''</script>")
fmt.Fprintf(res, "%d<br>", i)
if f, ok := res.(http.Flusher); ok {
f.Flush()
} else {
log.Println("Damn, no flush")
}
time.Sleep(1000 * time.Millisecond)
}
fmt.Fprintln(res, "</body>")
}
func main() {
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(":8080", nil))
}边栏推荐
猜你喜欢

单片机的优点和单片机开发的流程

WPF 实现柱形统计图

A50 - 基于51单片机的太阳能充电路灯设计
![[ Kitex Source Code Interpretation ] Request to retry](/img/d9/c1871c15cc9124e919d22c9adcc75b.png)
[ Kitex Source Code Interpretation ] Request to retry

B49 - 基于STM32单片机的心率血氧检测与远程定位报警装置

为了高性能、超大规模的模型训练,这个组合“出道”了

B45 - 基于STM32单片机的家庭防火防盗系统的设计

kubernetes之helm简介、安装、配置

B43 - 基于STM32单片机的自动视力检测仪

B44 - Based on stm32 bluetooth intelligent voice recognition classification broadcast trash
随机推荐
A48基于NRF24L01的无线心率血氧体温检测
Sigrity PowerSI Characteristic Impedance and Coupling Simulation
kubernetes之helm简介、安装、配置
qiucode.cn网站之文章详情实现代码块可点击按钮进行复制
MySQL的索引你了解吗
生产者-消费者线程模型学习
反转链表的多种写法(武器库了属于是)
2022国赛Ezpop
PADS生成位号图
B46 - STM32太阳能充电智能心率监测骑行仪
Optimization of a piece of JDBC code (Part 1)
Vim practical skills_2. Normal mode and insert mode
在 ASP.NET Core 中上传文件
MySQL索引的B+树到底有多高?
What is hardware integrated development?What are the cores of hardware integrated development?
Arrow parquet 之 String Reader
关于聊天机器人,跨境电商人必须知道这些…
面试中老生常谈的MySQL问答集锦夯实基础
The article details of the qiucode.cn website realize the code block can be copied by clicking the button
利用C#传输Json数据