pull/463/head
withchao 1 year ago
parent 0642f97e12
commit 12dd42c60d

@ -33,10 +33,11 @@ func NewMinioInterface() (Interface, error) {
} }
ctx, cancel := context.WithTimeout(context.Background(), time.Second*20) ctx, cancel := context.WithTimeout(context.Background(), time.Second*20)
defer cancel() defer cancel()
initBucket := func(ctx context.Context) error {
for _, bucket := range utils.Distinct([]string{conf.TempBucket, conf.DataBucket}) { for _, bucket := range utils.Distinct([]string{conf.TempBucket, conf.DataBucket}) {
exists, err := client.BucketExists(ctx, bucket) exists, err := client.BucketExists(ctx, bucket)
if err != nil { if err != nil {
return nil, fmt.Errorf("minio bucket %s exists %w", bucket, err) return fmt.Errorf("minio bucket %s exists %w", bucket, err)
} }
if exists { if exists {
continue continue
@ -46,9 +47,14 @@ func NewMinioInterface() (Interface, error) {
ObjectLocking: conf.IsDistributedMod, ObjectLocking: conf.IsDistributedMod,
} }
if err := client.MakeBucket(ctx, bucket, opt); err != nil { if err := client.MakeBucket(ctx, bucket, opt); err != nil {
return nil, fmt.Errorf("minio make bucket %s %w", bucket, err) return fmt.Errorf("minio make bucket %s %w", bucket, err)
} }
} }
return nil
}
if err := initBucket(ctx); err != nil {
fmt.Println("minio init error:", err)
}
return &minioImpl{ return &minioImpl{
client: client, client: client,
tempBucket: conf.TempBucket, tempBucket: conf.TempBucket,

Loading…
Cancel
Save