beam/examples/beamsh: use beam.Router to simplify 'trace'

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
Solomon Hykes 2014-04-02 20:03:17 -07:00
parent 1dbb699e6a
commit df3bbb2875

View file

@ -188,23 +188,13 @@ func CmdExec(args []string, stdout, stderr io.Writer, in beam.Receiver, out beam
}
func CmdTrace(args []string, stdout, stderr io.Writer, in beam.Receiver, out beam.Sender) {
for {
p, a, err := in.Receive()
if err != nil {
return
}
var msg string
if pretty := data.Message(string(p)).Pretty(); pretty != "" {
msg = pretty
} else {
msg = string(p)
}
if a != nil {
msg = fmt.Sprintf("%s [%d]", msg, a.Fd())
}
fmt.Printf("===> %s\n", msg)
out.Send(p, a)
}
r := beam.NewRouter(out)
r.NewRoute().All().Handler(func(payload []byte, attachment *os.File) error {
fmt.Printf("===> %s\n", beam.MsgDesc(payload, attachment))
out.Send(payload, attachment)
return nil
})
beam.Copy(r, in)
}
func CmdEmit(args []string, stdout, stderr io.Writer, in beam.Receiver, out beam.Sender) {