ipld-eth-server/vendor/github.com/goware/prefixer
2018-09-17 13:25:19 -05:00
..
example use Sup deployment tool to deploy to staging 2018-09-17 13:25:19 -05:00
.travis.yml use Sup deployment tool to deploy to staging 2018-09-17 13:25:19 -05:00
doc.go use Sup deployment tool to deploy to staging 2018-09-17 13:25:19 -05:00
LICENSE use Sup deployment tool to deploy to staging 2018-09-17 13:25:19 -05:00
prefixer_test.go use Sup deployment tool to deploy to staging 2018-09-17 13:25:19 -05:00
prefixer.go use Sup deployment tool to deploy to staging 2018-09-17 13:25:19 -05:00
README.md use Sup deployment tool to deploy to staging 2018-09-17 13:25:19 -05:00

Prefixer

Golang's io.Reader wrapper prepending every line with a given string.

GoDoc Travis

Use cases

  1. 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
    
  2. 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
    
  3. 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.