MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / callWithClient

Function callWithClient

storage/s3/storage.go:200–223  ·  view source on GitHub ↗

callWithClient is a helper function to call S3 client method with automatic region error handling

(s *Storage, bucket string, fn func(client s3Client) (*T, error))

Source from the content-addressed store, hash-verified

198// callWithClient is a helper function to call S3 client method with automatic region
199// error handling
200func callWithClient[T any](s *Storage, bucket string, fn func(client s3Client) (*T, error)) (*T, s3Client, error) {
201 client := s.getBucketClient(bucket)
202
203 r, err := fn(client)
204
205 if err != nil {
206 // Check if the error is the region mismatch error.
207 // If so, create a new client with the correct region and retry the request.
208 if region := regionFromError(err); len(region) != 0 {
209 client, err = s.createBucketClient(bucket, region)
210 if err != nil {
211 return nil, nil, err
212 }
213
214 r, err = fn(client)
215 }
216 }
217
218 if err != nil {
219 return nil, nil, err
220 }
221
222 return r, client, nil
223}

Callers 1

GetObjectMethod · 0.85

Calls 3

regionFromErrorFunction · 0.85
getBucketClientMethod · 0.80
createBucketClientMethod · 0.80

Tested by

no test coverage detected