.. | ||
example | ||
.travis.yml | ||
doc.go | ||
LICENSE | ||
prefixer_test.go | ||
prefixer.go | ||
README.md |
Prefixer
Golang's io.Reader wrapper prepending every line with a given string.
Use cases
-
Logger that prefixes every line with a timestamp etc.
16:54:49 My awesome server | Creating etcd client pointing to http://localhost:4001 16:54:49 My awesome server | Listening on http://localhost:8080 16:54:49 My awesome server | [restful/swagger] listing is available at 127.0.0.1:8080/swaggerapi
-
SSH multiplexer prepending output from multiple servers with a hostname
host1.example.com | SUCCESS host2.example.com | SUCCESS host3.example.com | -bash: cd: workdir: No such file or directory host4.example.com | SUCCESS
-
Create an email reply (
"> "
prefix) from any text easily.$ ./prefix Dear John, did you know that https://github.com/goware/prefixer is a golang pkg that prefixes every line with a given string and accepts any io.Reader? Cheers, - Jane ^D > Dear John, > did you know that https://github.com/goware/prefixer is a golang pkg > that prefixes every line with a given string and accepts any io.Reader? > > Cheers, > - Jane
Example
See the "Prefix Line Reader" example.
package main
import (
"io/ioutil"
"os"
"github.com/goware/prefixer"
)
func main() {
// Prefixer accepts anything that implements io.Reader interface
prefixReader := prefixer.New(os.Stdin, "> ")
// Read all prefixed lines from STDIN into a buffer
buffer, _ := ioutil.ReadAll(prefixReader)
// Write buffer to STDOUT
os.Stdout.Write(buffer)
}
License
Prefixer is licensed under the MIT License.