https://github.com/mitchellh/prefixedio
Golang library that demultiplexes line-oriented data from an io.Reader into multiple io.Readers based on a prefix.
https://github.com/mitchellh/prefixedio
Last synced: 12 months ago
JSON representation
Golang library that demultiplexes line-oriented data from an io.Reader into multiple io.Readers based on a prefix.
- Host: GitHub
- URL: https://github.com/mitchellh/prefixedio
- Owner: mitchellh
- License: mit
- Created: 2014-06-10T06:29:49.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2019-02-13T21:39:02.000Z (over 7 years ago)
- Last Synced: 2025-04-10T05:59:26.138Z (about 1 year ago)
- Language: Go
- Size: 10.7 KB
- Stars: 45
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# prefixedio
`prefixedio` (Golang package: `prefixedio`) is a package for Go
that takes an `io.Reader` and de-multiplexes line-oriented data based
on a line prefix to a set of readers.
## Installation and Usage
Install using `go get github.com/mitchellh/prefixedio`.
Full documentation is available at
http://godoc.org/github.com/mitchellh/prefixedio
Below is an example of its usage ignoring errors:
```go
// Assume r is some set io.Reader. Perhaps a file, network, anything.
var r io.Reader
// Initialize the prefixed reader
pr, _ := prefixedio.NewReader(r)
// Grab readers for a couple prefixes
errR, _ := pr.Prefix("err: ")
outR, _ := pr.Prefix("out: ")
// Copy the data to different places based on the prefix
go io.Copy(os.Stderr, errR)
go io.Copy(os.Stdout, outR)
```