github.com/chenchun/docker@v1.3.2-0.20150629222414-20467faf132b/daemon/attach.go (about) 1 package daemon 2 3 import ( 4 "io" 5 6 "github.com/docker/docker/pkg/stdcopy" 7 ) 8 9 type ContainerAttachWithLogsConfig struct { 10 InStream io.ReadCloser 11 OutStream io.Writer 12 UseStdin, UseStdout, UseStderr bool 13 Logs, Stream bool 14 } 15 16 func (daemon *Daemon) ContainerAttachWithLogs(name string, c *ContainerAttachWithLogsConfig) error { 17 container, err := daemon.Get(name) 18 if err != nil { 19 return err 20 } 21 22 var errStream io.Writer 23 24 if !container.Config.Tty { 25 errStream = stdcopy.NewStdWriter(c.OutStream, stdcopy.Stderr) 26 c.OutStream = stdcopy.NewStdWriter(c.OutStream, stdcopy.Stdout) 27 } else { 28 errStream = c.OutStream 29 } 30 31 var stdin io.ReadCloser 32 var stdout, stderr io.Writer 33 34 if c.UseStdin { 35 stdin = c.InStream 36 } 37 if c.UseStdout { 38 stdout = c.OutStream 39 } 40 if c.UseStderr { 41 stderr = errStream 42 } 43 44 return container.AttachWithLogs(stdin, stdout, stderr, c.Logs, c.Stream) 45 } 46 47 type ContainerWsAttachWithLogsConfig struct { 48 InStream io.ReadCloser 49 OutStream, ErrStream io.Writer 50 Logs, Stream bool 51 } 52 53 func (daemon *Daemon) ContainerWsAttachWithLogs(name string, c *ContainerWsAttachWithLogsConfig) error { 54 container, err := daemon.Get(name) 55 if err != nil { 56 return err 57 } 58 59 return container.AttachWithLogs(c.InStream, c.OutStream, c.ErrStream, c.Logs, c.Stream) 60 }