@@ -58,6 +58,7 @@ func SetMaxGRPCLogLength(characterCount int) {
5858// The function tries to connect for 30 seconds, and returns an error if no connection has been established at that point.
5959// The function automatically disables TLS and adds interceptor for logging of all gRPC messages at level 5.
6060// If the metricsManager is 'nil', no metrics will be recorded on the gRPC calls.
61+ // The function behaviour can be tweaked with options.
6162//
6263// For a connection to a Unix Domain socket, the behavior after
6364// loosing the connection is configurable. The default is to
@@ -72,9 +73,10 @@ func SetMaxGRPCLogLength(characterCount int) {
7273// For other connections, the default behavior from gRPC is used and
7374// loss of connection is not detected reliably.
7475func Connect (address string , metricsManager metrics.CSIMetricsManager , options ... Option ) (* grpc.ClientConn , error ) {
75- options = append (options , withTimeout (time .Second * 30 ))
76+ // Prepend default options
77+ options = append ([]Option {WithTimeout (time .Second * 30 )}, options ... )
7678 if metricsManager != nil {
77- options = append (options , withMetrics (metricsManager ))
79+ options = append ([] Option { WithMetrics (metricsManager )}, options ... )
7880 }
7981 return connect (address , options )
8082}
@@ -114,15 +116,15 @@ func ExitOnConnectionLoss() func() bool {
114116 }
115117}
116118
117- // withTimeout adds a configurable timeout on the gRPC calls.
118- func withTimeout (timeout time.Duration ) Option {
119+ // WithTimeout adds a configurable timeout on the gRPC calls.
120+ func WithTimeout (timeout time.Duration ) Option {
119121 return func (o * options ) {
120122 o .timeout = timeout
121123 }
122124}
123125
124- // withMetrics enables the recording of metrics on the gRPC calls with the provided CSIMetricsManager.
125- func withMetrics (metricsManager metrics.CSIMetricsManager ) Option {
126+ // WithMetrics enables the recording of metrics on the gRPC calls with the provided CSIMetricsManager.
127+ func WithMetrics (metricsManager metrics.CSIMetricsManager ) Option {
126128 return func (o * options ) {
127129 o .metricsManager = metricsManager
128130 }
0 commit comments