Handlers can return io.Reader to stream response data. This example uses a pipe to send data in chunks with delays. See https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html
()
| 20 | // |
| 21 | // See https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html |
| 22 | func Example_ioReader() { |
| 23 | lambda.Start(func() (io.Reader, error) { |
| 24 | r, w := io.Pipe() |
| 25 | go func() { |
| 26 | defer w.Close() |
| 27 | _, _ = w.Write([]byte("<html><body>")) |
| 28 | time.Sleep(100 * time.Millisecond) |
| 29 | _, _ = w.Write([]byte("<h1>Hello</h1>")) |
| 30 | time.Sleep(100 * time.Millisecond) |
| 31 | _, _ = w.Write([]byte("<p>World!</p>")) |
| 32 | time.Sleep(100 * time.Millisecond) |
| 33 | _, _ = w.Write([]byte("</body></html>")) |
| 34 | }() |
| 35 | return r, nil |
| 36 | }) |
| 37 | } |
| 38 | |
| 39 | func ExampleWithContext() { |
| 40 | lambda.StartWithOptions( |