package stdin import ( "bufio" "fmt" "io" "os" "github.com/Shugyousha/stasher/input" "github.com/Shugyousha/stasher/registry" "github.com/Shugyousha/stasher/work" ) func init() { registry.Inputregistry["stdin"] = New } type StdinInput struct { retchan chan *work.Work } func New(map[string]string) input.Input { return &StdinInput{} } 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 } w := &work.Work{Data: bs} if err != nil { fmt.Printf("Error when reading input from Stdin: %q", err) w.SetError(err) } i.retchan <- w } close(i.retchan) }() return i.retchan }