2021-03-12 12:33:32 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-09-13 14:18:53 +00:00
|
|
|
|
|
|
|
"google.golang.org/grpc"
|
2021-03-12 12:33:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// CallOption is a messaging session option within Protobuf RPC.
|
|
|
|
type CallOption func(*callParameters)
|
|
|
|
|
|
|
|
type callParameters struct {
|
2024-09-13 14:18:53 +00:00
|
|
|
ctx context.Context // nolint:containedctx
|
|
|
|
dialer func(context.Context, grpc.ClientConnInterface) error
|
2021-03-12 12:33:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func defaultCallParameters() *callParameters {
|
|
|
|
return &callParameters{
|
2022-10-03 09:34:22 +00:00
|
|
|
ctx: context.Background(),
|
2021-03-12 12:33:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-03 09:34:22 +00:00
|
|
|
// WithContext returns option to specify call context. If provided, all network
|
|
|
|
// communications will be based on this context. Otherwise, context.Background()
|
|
|
|
// is used.
|
|
|
|
//
|
|
|
|
// Context SHOULD NOT be nil.
|
2021-03-12 12:33:32 +00:00
|
|
|
func WithContext(ctx context.Context) CallOption {
|
|
|
|
return func(prm *callParameters) {
|
2022-10-03 09:34:22 +00:00
|
|
|
prm.ctx = ctx
|
2021-03-12 12:33:32 +00:00
|
|
|
}
|
|
|
|
}
|
2024-09-13 14:18:53 +00:00
|
|
|
|
|
|
|
// WithDialer returns option to specify grpc dialer. If passed, it will be
|
|
|
|
// called after the connection is successfully created.
|
|
|
|
func WithDialer(dialer func(context.Context, grpc.ClientConnInterface) error) CallOption {
|
|
|
|
return func(prm *callParameters) {
|
|
|
|
prm.dialer = dialer
|
|
|
|
}
|
|
|
|
}
|