@@ -257,11 +257,11 @@ type Client interface {
257257// will return the already created instance. To create multiple instances of the Dapr client,
258258// use one of the parameterized factory functions:
259259//
260- // NewClientWithPort(port string) (client Client, err error)
261- // NewClientWithAddress(address string) (client Client, err error)
262- // NewClientWithConnection(conn *grpc.ClientConn) Client
263- // NewClientWithSocket(socket string) (client Client, err error)
264- func NewClient () (client Client , err error ) {
260+ // NewClientWithPort(port string, dialOpts ...grpc.DialOption ) (client Client, err error)
261+ // NewClientWithAddress(address string, dialOpts ...grpc.DialOption ) (client Client, err error)
262+ // NewClientWithConnection(conn *grpc.ClientConn, dialOpts ...grpc.DialOption ) Client
263+ // NewClientWithSocket(socket string, dialOpts ...grpc.DialOption ) (client Client, err error)
264+ func NewClient (dialOpts ... grpc. DialOption ) (client Client , err error ) {
265265 lock .Lock ()
266266 defer lock .Unlock ()
267267
@@ -271,7 +271,7 @@ func NewClient() (client Client, err error) {
271271
272272 addr , ok := os .LookupEnv (daprGRPCEndpointEnvVarName )
273273 if ok {
274- client , err = NewClientWithAddress (addr )
274+ client , err = NewClientWithAddress (addr , dialOpts ... )
275275 if err != nil {
276276 return nil , fmt .Errorf ("error creating %q client: %w" , daprGRPCEndpointEnvVarName , err )
277277 }
@@ -284,7 +284,7 @@ func NewClient() (client Client, err error) {
284284 port = daprPortDefault
285285 }
286286
287- c , err := NewClientWithPort (port )
287+ c , err := NewClientWithPort (port , dialOpts ... )
288288 if err != nil {
289289 return nil , fmt .Errorf ("error creating default client: %w" , err )
290290 }
@@ -293,8 +293,8 @@ func NewClient() (client Client, err error) {
293293 return defaultClient , nil
294294}
295295
296- func NewWorkflowClient () (* workflow.Client , error ) {
297- dclient , err := NewClient ()
296+ func NewWorkflowClient (dialOpts ... grpc. DialOption ) (* workflow.Client , error ) {
297+ dclient , err := NewClient (dialOpts ... )
298298 if err != nil {
299299 return nil , err
300300 }
@@ -303,22 +303,22 @@ func NewWorkflowClient() (*workflow.Client, error) {
303303}
304304
305305// NewClientWithPort instantiates Dapr using specific gRPC port.
306- func NewClientWithPort (port string ) (client Client , err error ) {
306+ func NewClientWithPort (port string , dialOpts ... grpc. DialOption ) (client Client , err error ) {
307307 if port == "" {
308308 return nil , errors .New ("nil port" )
309309 }
310- return NewClientWithAddress (net .JoinHostPort ("127.0.0.1" , port ))
310+ return NewClientWithAddress (net .JoinHostPort ("127.0.0.1" , port ), dialOpts ... )
311311}
312312
313313// NewClientWithAddress instantiates Dapr using specific address (including port).
314314// Deprecated: use NewClientWithAddressContext instead.
315- func NewClientWithAddress (address string ) (client Client , err error ) {
316- return NewClientWithAddressContext (context .Background (), address )
315+ func NewClientWithAddress (address string , dialOpts ... grpc. DialOption ) (client Client , err error ) {
316+ return NewClientWithAddressContext (context .Background (), address , dialOpts ... )
317317}
318318
319319// NewClientWithAddressContext instantiates Dapr using specific address (including port).
320320// Uses the provided context to create the connection.
321- func NewClientWithAddressContext (ctx context.Context , address string ) (client Client , err error ) {
321+ func NewClientWithAddressContext (ctx context.Context , address string , dialOpts ... grpc. DialOption ) (client Client , err error ) {
322322 if address == "" {
323323 return nil , errors .New ("empty address" )
324324 }
@@ -343,6 +343,8 @@ func NewClientWithAddressContext(ctx context.Context, address string) (client Cl
343343 authTokenStreamInterceptor (at ),
344344 }
345345
346+ opts = append (opts , dialOpts ... )
347+
346348 if parsedAddress .TLS {
347349 opts = append (opts , grpc .WithTransportCredentials (credentials .NewTLS (new (tls.Config ))))
348350 } else {
@@ -379,19 +381,25 @@ func getClientTimeoutSeconds() (int, error) {
379381}
380382
381383// NewClientWithSocket instantiates Dapr using specific socket.
382- func NewClientWithSocket (socket string ) (client Client , err error ) {
384+ func NewClientWithSocket (socket string , dialOpts ... grpc. DialOption ) (client Client , err error ) {
383385 if socket == "" {
384386 return nil , errors .New ("nil socket" )
385387 }
386388 at := newAuthToken ()
387389 logger .Printf ("dapr client initializing for: %s" , socket )
388390 addr := "unix://" + socket
389- conn , err := grpc . Dial ( //nolint:staticcheck
390- addr ,
391+
392+ opts := []grpc. DialOption {
391393 grpc .WithTransportCredentials (insecure .NewCredentials ()),
392394 grpc .WithUserAgent (userAgent ()),
393395 authTokenUnaryInterceptor (at ),
394396 authTokenStreamInterceptor (at ),
397+ }
398+
399+ opts = append (opts , dialOpts ... )
400+ conn , err := grpc .Dial ( //nolint:staticcheck
401+ addr ,
402+ opts ... ,
395403 )
396404 if err != nil {
397405 return nil , fmt .Errorf ("error creating connection to '%s': %w" , addr , err )
0 commit comments