From 26412f3077698dabcdbdf6a6e40276c56a6f74b5 Mon Sep 17 00:00:00 2001 From: Silvan Jegen Date: Fri, 9 Dec 2016 21:12:18 +0100 Subject: Reorganize files --- input/stdin.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 input/stdin.go (limited to 'input/stdin.go') diff --git a/input/stdin.go b/input/stdin.go new file mode 100644 index 0000000..5acfa5e --- /dev/null +++ b/input/stdin.go @@ -0,0 +1,36 @@ +package input + +import ( + "bufio" + "fmt" + "io" + "os" + + "github.com/Shugyousha/stasher/work" +) + +type StdinInput struct { + retchan chan *work.Work +} + +func (i *StdinInput) Start() chan *work.Work { + i.retchan = make(chan *work.Work, 100) + r := bufio.NewReader(os.Stdin) + + go func() { + for { + bs, err := r.ReadBytes(byte('\n')) + if err == io.EOF { + break + } + if err != nil { + fmt.Printf("Error when reading input from Stdin: %q", err) + os.Exit(1) + } + i.retchan <- &work.Work{Data: bs} + } + close(i.retchan) + }() + + return i.retchan +} -- cgit v1.2.3