container.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. Copyright 2020 Docker Compose CLI authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package compose
  14. import (
  15. "io"
  16. moby "github.com/docker/docker/api/types"
  17. )
  18. var _ io.ReadCloser = ContainerStdout{}
  19. // ContainerStdout implement ReadCloser for moby.HijackedResponse
  20. type ContainerStdout struct {
  21. moby.HijackedResponse
  22. }
  23. // Read implement io.ReadCloser
  24. func (l ContainerStdout) Read(p []byte) (n int, err error) {
  25. return l.Reader.Read(p)
  26. }
  27. // Close implement io.ReadCloser
  28. func (l ContainerStdout) Close() error {
  29. l.HijackedResponse.Close()
  30. return nil
  31. }
  32. var _ io.WriteCloser = ContainerStdin{}
  33. // ContainerStdin implement WriteCloser for moby.HijackedResponse
  34. type ContainerStdin struct {
  35. moby.HijackedResponse
  36. }
  37. // Write implement io.WriteCloser
  38. func (c ContainerStdin) Write(p []byte) (n int, err error) {
  39. return c.Conn.Write(p)
  40. }
  41. // Close implement io.WriteCloser
  42. func (c ContainerStdin) Close() error {
  43. return c.CloseWrite()
  44. }