Skip to content

Commit aaf03ae

Browse files
committed
blob/gcsblob: Allow providing options for storage.NewClient
1 parent e5b1bc6 commit aaf03ae

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Diff for: blob/gcsblob/gcsblob.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ type Options struct {
284284
// MakeSignBytes is a factory for functions that are being used in place of an empty SignBytes.
285285
// If your implementation of 'SignBytes' needs a request context, set this instead.
286286
MakeSignBytes func(requestCtx context.Context) SignBytesFunc
287+
288+
// ClientOptions are passed when constructing the storage.Client.
289+
ClientOptions []option.ClientOption
287290
}
288291

289292
// clear clears all the fields of o.
@@ -306,6 +309,7 @@ func openBucket(ctx context.Context, client *gcp.HTTPClient, bucketName string,
306309
return nil, errors.New("gcsblob.OpenBucket: bucketName is required")
307310
}
308311

312+
// We wrap the provided http.Client to add a Go CDK User-Agent.
309313
clientOpts := []option.ClientOption{option.WithHTTPClient(useragent.HTTPClient(&client.Client, "blob"))}
310314
if host := os.Getenv("STORAGE_EMULATOR_HOST"); host != "" {
311315
clientOpts = []option.ClientOption{
@@ -314,15 +318,14 @@ func openBucket(ctx context.Context, client *gcp.HTTPClient, bucketName string,
314318
option.WithHTTPClient(http.DefaultClient),
315319
}
316320
}
317-
318-
// We wrap the provided http.Client to add a Go CDK User-Agent.
321+
if opts == nil {
322+
opts = &Options{}
323+
}
324+
clientOpts = append(clientOpts, opts.ClientOptions...)
319325
c, err := storage.NewClient(ctx, clientOpts...)
320326
if err != nil {
321327
return nil, err
322328
}
323-
if opts == nil {
324-
opts = &Options{}
325-
}
326329
return &bucket{name: bucketName, client: c, opts: opts}, nil
327330
}
328331

0 commit comments

Comments
 (0)