Skip to content

Commit

Permalink
allow setting region via custom function (#1786)
Browse files Browse the repository at this point in the history
replaces #1783
  • Loading branch information
harshavardhana committed Mar 6, 2023
1 parent 9948a7b commit 5384d69
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ type Options struct {
Region string
BucketLookup BucketLookupType

// Allows setting a custom region lookup based on URL pattern
// not all URL patterns are covered by this library so if you
// have a custom endpoints with many regions you can use this
// function to perform region lookups appropriately.
CustomRegionViaURL func(u url.URL) string

// TrailingHeaders indicates server support of trailing headers.
// Only supported for v4 signatures.
TrailingHeaders bool
Expand Down Expand Up @@ -234,7 +240,11 @@ func privateNew(endpoint string, opts *Options) (*Client, error) {

// Sets custom region, if region is empty bucket location cache is used automatically.
if opts.Region == "" {
opts.Region = s3utils.GetRegionFromURL(*clnt.endpointURL)
if opts.CustomRegionViaURL != nil {
opts.Region = opts.CustomRegionViaURL(*clnt.endpointURL)
} else {
opts.Region = s3utils.GetRegionFromURL(*clnt.endpointURL)
}
}
clnt.region = opts.Region

Expand Down

0 comments on commit 5384d69

Please sign in to comment.