forked from linkerd/linkerd2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
66 lines (56 loc) · 1.37 KB
/
server.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
package proxy
import (
"io"
"net"
common "github.com/runconduit/conduit/controller/gen/common"
destination "github.com/runconduit/conduit/controller/gen/proxy/destination"
"github.com/runconduit/conduit/controller/util"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
)
type (
server struct {
destinationClient destination.DestinationClient
}
)
func (s *server) Get(dest *common.Destination, stream destination.Destination_GetServer) error {
log := log.WithFields(
log.Fields{
"scheme": dest.Scheme,
"path": dest.Path,
})
log.Debug("Get")
rsp, err := s.destinationClient.Get(stream.Context(), dest)
if err != nil {
log.Error(err)
return err
}
for {
update, err := rsp.Recv()
if err == io.EOF {
break
}
if err != nil {
log.Error(err)
return err
}
log.Debug("Get update: %v", update)
stream.Send(update)
}
log.Debug("Get complete")
return nil
}
/*
* The Proxy-API server accepts requests from proxy instances and forwards those
* requests to the appropriate controller service.
*/
func NewServer(addr string, destinationClient destination.DestinationClient) (*grpc.Server, net.Listener, error) {
lis, err := net.Listen("tcp", addr)
if err != nil {
return nil, nil, err
}
s := util.NewGrpcServer()
srv := server{destinationClient: destinationClient}
destination.RegisterDestinationServer(s, &srv)
return s, lis, nil
}