logs.go 464 B

1234567891011121314151617181920212223242526
  1. package streams
  2. import (
  3. "io"
  4. "google.golang.org/grpc"
  5. containersv1 "github.com/docker/api/protos/containers/v1"
  6. )
  7. // Log implements an io.Writer that proxies logs over a gRPC stream
  8. type Log struct {
  9. Stream grpc.ServerStream
  10. }
  11. func newStreamWriter(stream grpc.ServerStream) io.Writer {
  12. return &Log{
  13. Stream: stream,
  14. }
  15. }
  16. func (w *Log) Write(p []byte) (n int, err error) {
  17. return len(p), w.Stream.SendMsg(&containersv1.LogsResponse{
  18. Value: p,
  19. })
  20. }