@@ -43,23 +43,32 @@ func (s *DebugService) Debug(stream dbg.Debug_DebugServer) error {
43
43
return fmt .Errorf ("first message must contain debug request, not data" )
44
44
}
45
45
46
+ // launch debug recipe attaching stdin and out to grpc streaming
47
+ resp , err := cmd .Debug (stream .Context (), req ,
48
+ copyStream (func () ([]byte , error ) {
49
+ command , err := stream .Recv ()
50
+ return command .GetData (), err
51
+ }),
52
+ feedStream (func (data []byte ) {
53
+ stream .Send (& dbg.DebugResp {Data : data })
54
+ }))
55
+ if err != nil {
56
+ return (err )
57
+ }
58
+ return stream .Send (resp )
59
+ }
60
+
61
+ func copyStream (streamIn func () ([]byte , error )) io.Reader {
62
+
46
63
r , w := io .Pipe ()
47
64
go func () {
48
65
for {
49
- if command , err := stream . Recv (); err != nil {
66
+ if data , err := streamIn (); err != nil {
50
67
return
51
- } else if _ , err := w .Write (command . GetData () ); err != nil {
68
+ } else if _ , err := w .Write (data ); err != nil {
52
69
return
53
70
}
54
71
}
55
72
}()
56
-
57
- // launch debug recipe attaching stdin and out to grpc streaming
58
- resp , err := cmd .Debug (stream .Context (), req , r , feedStream (func (data []byte ) {
59
- stream .Send (& dbg.DebugResp {Data : data })
60
- }))
61
- if err != nil {
62
- return (err )
63
- }
64
- return stream .Send (resp )
73
+ return r
65
74
}
0 commit comments