Skip to content

Instantly share code, notes, and snippets.

@adrianlungu
Created December 6, 2017 13:17
Show Gist options
  • Save adrianlungu/6b5f30e4be85602288e35113ba40d903 to your computer and use it in GitHub Desktop.
Save adrianlungu/6b5f30e4be85602288e35113ba40d903 to your computer and use it in GitHub Desktop.
Golang streaming to http response #01
buf := make([]byte, 4096)
for {
n, err := gReader.Read(buf)
if err != nil {
if err == io.EOF {
_, err = c.Response().Write(buf[:n])
if err != nil {
return err
}
c.Response().Flush()
break
}
return err
}
_, err = c.Response().Write(buf[:n])
if err != nil {
return err
}
c.Response().Flush()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment