Created
December 15, 2016 19:05
-
-
Save caelifer/0e348225dcbc85772265d371bcd444d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Stolen from https://zupzup.org/io-pipe-go/ | |
pr, pw := io.Pipe() | |
go func() { | |
// close the writer, so the reader knows there's no more data | |
defer pw.Close() | |
// write json data to the PipeReader through the PipeWriter | |
if err := json.NewEncoder(pw).Encode(&PayLoad{Content: "Hello Pipe!"}); err != nil { | |
log.Fatal(err) | |
} | |
}() | |
// JSON from the PipeWriter lands in the PipeReader | |
// ...and we send it off... | |
if _, err := http.Post("http://example.com", "application/json", pr); err != nil { | |
log.Fatal(err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment