Pipe

将当前Reader pipe向Response,用于流式输出响应数据,节省内存使用。

Example

  1. package main
  2. import (
  3. "bytes"
  4. "github.com/vicanso/elton"
  5. "github.com/vicanso/elton/middleware"
  6. )
  7. func main() {
  8. e := elton.New()
  9. e.Use(middleware.NewDefaultResponder())
  10. e.GET("/", func(c *elton.Context) (err error) {
  11. buf := new(bytes.Buffer)
  12. for i := 0; i < 1000; i++ {
  13. buf.WriteString("Hello, World!\n")
  14. }
  15. _, _ = c.Pipe(buf)
  16. return
  17. })
  18. err := e.ListenAndServe(":3000")
  19. if err != nil {
  20. panic(err)
  21. }
  22. }