StartUpstreamServer starts a new upstream server with the given reader and writer
(reader io.Reader, writer io.Writer, options *UpstreamOptions)
| 40 | |
| 41 | // StartUpstreamServer starts a new upstream server with the given reader and writer |
| 42 | func StartUpstreamServer(reader io.Reader, writer io.Writer, options *UpstreamOptions) error { |
| 43 | pipe := util.NewStdStreamJoint(reader, writer, options.ExitOnClose) |
| 44 | lis := util.NewStdinListener() |
| 45 | done := make(chan error) |
| 46 | |
| 47 | // Compile ignore paths |
| 48 | ignoreMatcher, err := ignoreparser.CompilePaths(options.ExludePaths, logpkg.Discard) |
| 49 | if err != nil { |
| 50 | return errors.Wrap(err, "compile paths") |
| 51 | } |
| 52 | |
| 53 | go func() { |
| 54 | s := grpc.NewServer() |
| 55 | upstream := &Upstream{ |
| 56 | options: options, |
| 57 | ignoreMatcher: ignoreMatcher, |
| 58 | ping: &pingtimeout.PingTimeout{}, |
| 59 | } |
| 60 | |
| 61 | if options.Ping { |
| 62 | doneChan := make(chan struct{}) |
| 63 | defer close(doneChan) |
| 64 | upstream.ping.Start(doneChan) |
| 65 | } |
| 66 | |
| 67 | remote.RegisterUpstreamServer(s, upstream) |
| 68 | reflection.Register(s) |
| 69 | |
| 70 | done <- s.Serve(lis) |
| 71 | }() |
| 72 | |
| 73 | lis.Ready(pipe) |
| 74 | return <-done |
| 75 | } |
| 76 | |
| 77 | // Upstream is the implementation for the upstream server |
| 78 | type Upstream struct { |