@@ -116,6 +116,11 @@ func (gcs *GCS) Connect(ctx context.Context) error {
116116 clientOptions = append (clientOptions , option .WithoutAuthentication ())
117117 }
118118
119+ // storageClientOptions will be used for storage.NewClient
120+ // we need to separate them to avoid "multiple credential options provided" error
121+ storageClientOptions := make ([]option.ClientOption , len (clientOptions ))
122+ copy (storageClientOptions , clientOptions )
123+
119124 if gcs .Config .ForceHttp {
120125 customTransport := & http.Transport {
121126 WriteBufferSize : 128 * 1024 ,
@@ -152,8 +157,13 @@ func (gcs *GCS) Connect(ctx context.Context) error {
152157 return errors .Wrap (err , "failed to create GCP transport" )
153158 }
154159
155- clientOptions = append (clientOptions , option .WithHTTPClient (gcpTransport ))
156-
160+ storageClientOptions = []option.ClientOption {
161+ option .WithTelemetryDisabled (),
162+ option .WithHTTPClient (gcpTransport ),
163+ }
164+ if gcs .Config .Endpoint != "" {
165+ storageClientOptions = append (storageClientOptions , option .WithEndpoint (endpoint ))
166+ }
157167 }
158168
159169 if gcs .Config .Debug {
@@ -170,20 +180,26 @@ func (gcs *GCS) Connect(ctx context.Context) error {
170180 return errors .Wrap (err , "googleHTTPTransport.NewClient error" )
171181 }
172182 debugClient .Transport = debugGCSTransport {base : debugClient .Transport }
173- clientOptions = append (clientOptions , option .WithHTTPClient (debugClient ))
183+ storageClientOptions = []option.ClientOption {
184+ option .WithTelemetryDisabled (),
185+ option .WithHTTPClient (debugClient ),
186+ }
187+ if gcs .Config .Endpoint != "" {
188+ storageClientOptions = append (storageClientOptions , option .WithEndpoint (endpoint ))
189+ }
174190 }
175191
176192 factory := pool .NewPooledObjectFactorySimple (
177193 func (context.Context ) (interface {}, error ) {
178- sClient , err := storage .NewClient (ctx , clientOptions ... )
194+ sClient , err := storage .NewClient (ctx , storageClientOptions ... )
179195 if err != nil {
180196 return nil , err
181197 }
182198 return & clientObject {Client : sClient }, nil
183199 })
184200 gcs .clientPool = pool .NewObjectPoolWithDefaultConfig (ctx , factory )
185201 gcs .clientPool .Config .MaxTotal = gcs .Config .ClientPoolSize * 3
186- gcs .client , err = storage .NewClient (ctx , clientOptions ... )
202+ gcs .client , err = storage .NewClient (ctx , storageClientOptions ... )
187203 return err
188204}
189205
0 commit comments