fix double init error
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
28
s3.go
28
s3.go
@@ -21,10 +21,11 @@ import (
|
||||
var keyRegex = regexp.MustCompile("[^a-zA-Z0-9]+")
|
||||
|
||||
type s3Store struct {
|
||||
client *minio.Client
|
||||
opts store.Options
|
||||
endpoint string
|
||||
mopts *minio.Options
|
||||
client *minio.Client
|
||||
opts store.Options
|
||||
endpoint string
|
||||
mopts *minio.Options
|
||||
connected bool
|
||||
}
|
||||
|
||||
func getBucket(ctx context.Context) string {
|
||||
@@ -43,15 +44,18 @@ func NewStore(opts ...store.Option) store.Store {
|
||||
}
|
||||
|
||||
func (s *s3Store) Connect(ctx context.Context) error {
|
||||
if s.client == nil {
|
||||
client, err := minio.New(s.endpoint, s.mopts)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error connecting to store: %w", err)
|
||||
}
|
||||
|
||||
s.client = client
|
||||
if s.connected {
|
||||
return nil
|
||||
}
|
||||
|
||||
client, err := minio.New(s.endpoint, s.mopts)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error connecting to store: %w", err)
|
||||
}
|
||||
|
||||
s.client = client
|
||||
s.connected = true
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -65,7 +69,7 @@ func (s *s3Store) Init(opts ...store.Option) error {
|
||||
}
|
||||
|
||||
var akey, skey string
|
||||
var endpoint string
|
||||
endpoint := s.endpoint
|
||||
|
||||
if s.opts.Context != nil {
|
||||
if v, ok := s.opts.Context.Value(accessKey{}).(string); ok && v != "" {
|
||||
|
||||
Reference in New Issue
Block a user