fill region option in minio.Options

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-02-04 09:05:03 +03:00
parent 392db01d40
commit 6efc858dbd

13
s3.go
View File

@ -69,6 +69,7 @@ func (s *s3Store) Init(opts ...store.Option) error {
} }
var akey, skey string var akey, skey string
var region string
endpoint := s.endpoint endpoint := s.endpoint
if s.opts.Context != nil { 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 != "" { if v, ok := s.opts.Context.Value(endpointKey{}).(string); ok && v != "" {
endpoint = v endpoint = v
} }
if v, ok := s.opts.Context.Value(regionKey{}).(string); ok && v != "" {
region = v
}
} }
if len(akey) > 0 && len(skey) > 0 { if len(akey) > 0 && len(skey) > 0 {
@ -110,6 +115,7 @@ func (s *s3Store) Init(opts ...store.Option) error {
ts.TLSClientConfig = s.opts.TLSConfig ts.TLSClientConfig = s.opts.TLSConfig
} }
s.mopts.Transport = ts s.mopts.Transport = ts
s.mopts.Region = region
s.endpoint = endpoint s.endpoint = endpoint
@ -186,13 +192,8 @@ func (s *s3Store) Write(ctx context.Context, key string, val interface{}, opts .
bucket = options.Namespace bucket = options.Namespace
} }
var region string
mputopts := minio.PutObjectOptions{} mputopts := minio.PutObjectOptions{}
if v, ok := s.opts.Context.Value(regionKey{}).(string); ok && v != "" {
region = v
}
if options.Context != nil { if options.Context != nil {
if v, ok := options.Context.Value(contentTypeKey{}).(string); ok && v != "" { if v, ok := options.Context.Value(contentTypeKey{}).(string); ok && v != "" {
mputopts.ContentType = 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 { if ok, err := s.client.BucketExists(ctx, bucket); err != nil {
return err return err
} else if !ok { } 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 { if err := s.client.MakeBucket(ctx, bucket, opts); err != nil {
return err return err
} }