1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
package gitaly
import (
"context"
"fmt"
"io"
"net/http"
"gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v16/streamio"
)
type DiffClient struct {
gitalypb.DiffServiceClient
}
func (client *DiffClient) SendRawDiff(ctx context.Context, w http.ResponseWriter, request *gitalypb.RawDiffRequest) error {
c, err := client.RawDiff(ctx, request)
if err != nil {
return fmt.Errorf("rpc failed: %v", err)
}
w.Header().Del("Content-Length")
rr := streamio.NewReader(func() ([]byte, error) {
resp, err := c.Recv()
return resp.GetData(), err
})
if _, err := io.Copy(w, rr); err != nil {
return fmt.Errorf("copy rpc data: %v", err)
}
return nil
}
func (client *DiffClient) SendRawPatch(ctx context.Context, w http.ResponseWriter, request *gitalypb.RawPatchRequest) error {
c, err := client.RawPatch(ctx, request)
if err != nil {
return fmt.Errorf("rpc failed: %v", err)
}
w.Header().Del("Content-Length")
rr := streamio.NewReader(func() ([]byte, error) {
resp, err := c.Recv()
return resp.GetData(), err
})
if _, err := io.Copy(w, rr); err != nil {
return fmt.Errorf("copy rpc data: %v", err)
}
return nil
}
|