mirror of
https://github.com/gusaul/grpcox.git
synced 2024-12-25 18:10:11 +00:00
update pipe commit output to handling huge output
This commit is contained in:
parent
30fef12ac9
commit
8aa67b6529
|
@ -204,6 +204,15 @@ func (r *Resource) Invoke(ctx context.Context, symbol string, in io.Reader) (str
|
||||||
}
|
}
|
||||||
os.Stdout = w
|
os.Stdout = w
|
||||||
|
|
||||||
|
// copy the output in a separate goroutine so printing can't block indefinitely
|
||||||
|
outC := make(chan string, 1)
|
||||||
|
var buf bytes.Buffer
|
||||||
|
go func() {
|
||||||
|
io.Copy(&buf, f)
|
||||||
|
outC <- buf.String()
|
||||||
|
f.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
rf, formatter, err := grpcurl.RequestParserAndFormatterFor(grpcurl.Format("json"), r.descSource, false, true, in)
|
rf, formatter, err := grpcurl.RequestParserAndFormatterFor(grpcurl.Format("json"), r.descSource, false, true, in)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, err
|
return "", 0, err
|
||||||
|
@ -213,6 +222,7 @@ func (r *Resource) Invoke(ctx context.Context, symbol string, in io.Reader) (str
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
err = grpcurl.InvokeRPC(ctx, r.descSource, r.clientConn, symbol, r.headers, h, rf.Next)
|
err = grpcurl.InvokeRPC(ctx, r.descSource, r.clientConn, symbol, r.headers, h, rf.Next)
|
||||||
end := time.Now().Sub(start) / time.Millisecond
|
end := time.Now().Sub(start) / time.Millisecond
|
||||||
|
w.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", end, err
|
return "", end, err
|
||||||
}
|
}
|
||||||
|
@ -221,15 +231,6 @@ func (r *Resource) Invoke(ctx context.Context, symbol string, in io.Reader) (str
|
||||||
return "", end, fmt.Errorf(h.Status.Message())
|
return "", end, fmt.Errorf(h.Status.Message())
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy the output in a separate goroutine so printing can't block indefinitely
|
|
||||||
outC := make(chan string)
|
|
||||||
go func() {
|
|
||||||
var buf bytes.Buffer
|
|
||||||
io.Copy(&buf, f)
|
|
||||||
outC <- buf.String()
|
|
||||||
}()
|
|
||||||
|
|
||||||
w.Close()
|
|
||||||
out := <-outC
|
out := <-outC
|
||||||
|
|
||||||
return out, end, nil
|
return out, end, nil
|
||||||
|
|
Loading…
Reference in New Issue
Block a user