From 6efc858dbd1d0529ef5da2c68c5992c437a1242e Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 4 Feb 2021 09:05:03 +0300 Subject: [PATCH] fill region option in minio.Options Signed-off-by: Vasiliy Tolstov --- s3.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/s3.go b/s3.go index 018e1ca..ed629ba 100644 --- a/s3.go +++ b/s3.go @@ -69,6 +69,7 @@ func (s *s3Store) Init(opts ...store.Option) error { } var akey, skey string + var region string endpoint := s.endpoint if s.opts.Context != nil { @@ -81,6 +82,10 @@ func (s *s3Store) Init(opts ...store.Option) error { if v, ok := s.opts.Context.Value(endpointKey{}).(string); ok && v != "" { endpoint = v } + if v, ok := s.opts.Context.Value(regionKey{}).(string); ok && v != "" { + region = v + } + } if len(akey) > 0 && len(skey) > 0 { @@ -110,6 +115,7 @@ func (s *s3Store) Init(opts ...store.Option) error { ts.TLSClientConfig = s.opts.TLSConfig } s.mopts.Transport = ts + s.mopts.Region = region s.endpoint = endpoint @@ -186,13 +192,8 @@ func (s *s3Store) Write(ctx context.Context, key string, val interface{}, opts . bucket = options.Namespace } - var region string mputopts := minio.PutObjectOptions{} - if v, ok := s.opts.Context.Value(regionKey{}).(string); ok && v != "" { - region = v - } - if options.Context != nil { if v, ok := options.Context.Value(contentTypeKey{}).(string); ok && v != "" { mputopts.ContentType = v @@ -211,7 +212,7 @@ func (s *s3Store) Write(ctx context.Context, key string, val interface{}, opts . if ok, err := s.client.BucketExists(ctx, bucket); err != nil { return err } else if !ok { - opts := minio.MakeBucketOptions{Region: region} + opts := minio.MakeBucketOptions{Region: s.mopts.Region} if err := s.client.MakeBucket(ctx, bucket, opts); err != nil { return err }