rearrange init code

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-02-04 10:36:59 +03:00
parent 560cb01564
commit 0e452f4dc7

32
s3.go
View File

@ -81,21 +81,6 @@ 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 {
s.mopts.Creds = creds.NewStaticV2(akey, skey, "")
}
if len(endpoint) == 0 {
return fmt.Errorf("missing Endpoint option")
}
var secure bool var secure bool
if strings.HasPrefix(endpoint, "https://") || s.opts.TLSConfig != nil { if strings.HasPrefix(endpoint, "https://") || s.opts.TLSConfig != nil {
@ -110,14 +95,25 @@ func (s *s3Store) Init(opts ...store.Option) error {
if err != nil { if err != nil {
return fmt.Errorf("init error: %w", err) return fmt.Errorf("init error: %w", err)
} }
if s.opts.TLSConfig != nil { if s.opts.TLSConfig != nil {
ts.TLSClientConfig = s.opts.TLSConfig ts.TLSClientConfig = s.opts.TLSConfig
} }
s.mopts.Transport = ts
s.mopts.Region = region
s.mopts.Transport = ts
s.mopts.Secure = secure
s.endpoint = endpoint s.endpoint = endpoint
}
if v, ok := s.opts.Context.Value(regionKey{}).(string); ok && v != "" {
region = v
}
}
if len(akey) > 0 && len(skey) > 0 {
s.mopts.Creds = creds.NewStaticV2(akey, skey, "")
}
s.mopts.Region = region
return nil return nil
} }