frostfs-api-go/rpc/client/call_options.go
Dmitrii Stepanov 13fa0da374
All checks were successful
Tests and linters / Lint (pull_request) Successful in 41s
DCO action / DCO (pull_request) Successful in 45s
Tests and linters / Tests (pull_request) Successful in 46s
Tests and linters / Tests with -race (pull_request) Successful in 56s
[#117] rpc: Allow to specify custom gRPC dialer
After grpc upgrade there is no DialContext call.
So connection is not actually established after created.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2024-09-16 12:35:37 +03:00

40 lines
1,018 B
Go

package client
import (
"context"
"google.golang.org/grpc"
)
// CallOption is a messaging session option within Protobuf RPC.
type CallOption func(*callParameters)
type callParameters struct {
ctx context.Context // nolint:containedctx
dialer func(context.Context, grpc.ClientConnInterface) error
}
func defaultCallParameters() *callParameters {
return &callParameters{
ctx: context.Background(),
}
}
// 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.
func WithContext(ctx context.Context) CallOption {
return func(prm *callParameters) {
prm.ctx = ctx
}
}
// 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
}
}