Pipe
将当前Reader pipe向Response,用于流式输出响应数据,节省内存使用。
Example
package main
import (
"bytes"
"github.com/vicanso/elton"
"github.com/vicanso/elton/middleware"
)
func main() {
e := elton.New()
e.Use(middleware.NewDefaultResponder())
e.GET("/", func(c *elton.Context) (err error) {
buf := new(bytes.Buffer)
for i := 0; i < 1000; i++ {
buf.WriteString("Hello, World!\n")
}
_, _ = c.Pipe(buf)
return
})
err := e.ListenAndServe(":3000")
if err != nil {
panic(err)
}
}