Skip to content

Commit 13ee978

Browse files
committed
pkg/stub: add support for extra ttrpc options.
Add WithTTRPCOptions() which can be used to pass extra client and server options to ttrpc. Signed-off-by: Krisztian Litkey <[email protected]>
1 parent c4e2f81 commit 13ee978

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

pkg/stub/stub.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,15 @@ func WithDialer(d func(string) (stdnet.Conn, error)) Option {
227227
}
228228
}
229229

230+
// WithTTRPCOptions sets extra client and server options to use for ttrpc .
231+
func WithTTRPCOptions(clientOpts []ttrpc.ClientOpts, serverOpts []ttrpc.ServerOpt) Option {
232+
return func(s *stub) error {
233+
s.clientOpts = append(s.clientOpts, clientOpts...)
234+
s.serverOpts = append(s.serverOpts, serverOpts...)
235+
return nil
236+
}
237+
}
238+
230239
// stub implements Stub.
231240
type stub struct {
232241
sync.Mutex
@@ -239,6 +248,8 @@ type stub struct {
239248
dialer func(string) (stdnet.Conn, error)
240249
conn stdnet.Conn
241250
onClose func()
251+
serverOpts []ttrpc.ServerOpt
252+
clientOpts []ttrpc.ClientOpts
242253
rpcm multiplex.Mux
243254
rpcl stdnet.Listener
244255
rpcs *ttrpc.Server
@@ -334,7 +345,7 @@ func (stub *stub) Start(ctx context.Context) (retErr error) {
334345
}
335346
}()
336347

337-
rpcs, err := ttrpc.NewServer()
348+
rpcs, err := ttrpc.NewServer(stub.serverOpts...)
338349
if err != nil {
339350
return fmt.Errorf("failed to create ttrpc server: %w", err)
340351
}
@@ -351,11 +362,13 @@ func (stub *stub) Start(ctx context.Context) (retErr error) {
351362
if err != nil {
352363
return fmt.Errorf("failed to multiplex ttrpc client connection: %w", err)
353364
}
354-
rpcc := ttrpc.NewClient(conn,
365+
366+
clientOpts := []ttrpc.ClientOpts{
355367
ttrpc.WithOnClose(func() {
356368
stub.connClosed()
357369
}),
358-
)
370+
}
371+
rpcc := ttrpc.NewClient(conn, append(clientOpts, stub.clientOpts...)...)
359372
defer func() {
360373
if retErr != nil {
361374
rpcc.Close()

0 commit comments

Comments
 (0)