Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/unloop/gopipe
Golang pipe http response
https://github.com/unloop/gopipe
backend go golang http library pipe stream streaming utils
Last synced: about 7 hours ago
JSON representation
Golang pipe http response
- Host: GitHub
- URL: https://github.com/unloop/gopipe
- Owner: unloop
- License: mit
- Created: 2016-12-21T16:51:52.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2016-12-22T13:27:18.000Z (almost 8 years ago)
- Last Synced: 2024-06-20T05:05:54.392Z (5 months ago)
- Topics: backend, go, golang, http, library, pipe, stream, streaming, utils
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
gopipe
=======
Golang pipe http response
## Installation and usage
The import path for the package is github.com/unloop/gopipe.
To install it, run: `go get github.com/unloop/gopipe`
## Example: pipe to http.ResponseWriter
```go
package mainimport (
"github.com/unloop/gopipe"
"net/http"
"io"
"fmt"
)func handler(w http.ResponseWriter, r *http.Request) {
var readCloser io.ReadCloser
/* do something */
defer readCloser.Close()
s := stream.New(w).SetBuffer(2048)
go s.Pipe(&readCloser)notify := w.(http.CloseNotifier).CloseNotify()
go func() {
<-notify
fmt.Println("HTTP connection just closed.")
s.Close()
}()return
}func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":3000", nil)
}
```## Example: pipe to stdout
```go
package mainimport (
"github.com/unloop/gopipe"
"io"
"fmt"
)type Writer struct {
io.Writer
}func (Writer) Write(p []byte) (int, error) {
return fmt.Print(string(p))
}func main() {
var readCloser io.ReadCloser
/* do something */
defer readCloser.Close()
stream.New(Writer{}).Pipe(&readCloser)return
}
```