-
Notifications
You must be signed in to change notification settings - Fork 11
/
web_server_status.go
69 lines (57 loc) · 1.48 KB
/
web_server_status.go
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package transport //nolint:dupl
import (
"bytes"
"context"
"io"
grpctransport "github.com/go-kit/kit/transport/grpc"
"github.com/marmotedu/errors"
"google.golang.org/grpc"
pbv1 "github.com/ClessLi/bifrost/api/protobuf-spec/bifrostpb/v1"
)
type WebServerStatusTransport interface {
Get() Client
}
type webServerStatusTransport struct {
getClient Client
}
func (w *webServerStatusTransport) Get() Client {
return w.getClient
}
func newWebServerStatusClient(
conn *grpc.ClientConn,
requestFunc grpctransport.EncodeRequestFunc,
responseFunc grpctransport.DecodeResponseFunc,
) Client {
cli := pbv1.NewWebServerStatusClient(conn)
return newClient(func(ctx context.Context, request interface{}) (response interface{}, err error) {
req, err := requestFunc(ctx, request)
if err != nil {
return nil, err
}
stream, err := cli.Get(ctx, req.(*pbv1.Null))
if err != nil {
return nil, err
}
buf := bytes.NewBuffer(nil)
for {
d, err := stream.Recv()
if err != nil && !errors.Is(err, io.EOF) {
return nil, err
}
if errors.Is(err, io.EOF) {
break
}
buf.Write(d.GetJsonData())
}
return responseFunc(ctx, &pbv1.Metrics{JsonData: buf.Bytes()})
})
}
func newWebServerStatusTransport(transport *transport) WebServerStatusTransport {
return &webServerStatusTransport{
getClient: newWebServerStatusClient(
transport.conn,
transport.encoderFactory.WebServerStatus().EncodeRequest,
transport.decoderFactory.WebServerStatus().DecodeResponse,
),
}
}