Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Delete All the objects in the bucket
package main
import (
"log"
"github.com/minio/minio-go"
"fmt"
)
func main() {
accessKey := "accessKey"
secretKey := "secretKey"
url := "url"
myBucket := "minio-bucket1"
s3Client, err := minio.NewV2(url, accessKey, secretKey, true)
if err != nil {
log.Fatalln(err)
}
// Create a done channel to control 'ListObjects' go routine.
doneCh := make(chan struct{})
// Indicate to our routine to exit cleanly upon return.
defer close(doneCh)
var arr []minio.ObjectInfo
// List all objects from a bucket-name with a matching prefix.
for object := range s3Client.ListObjects(myBucket, "", false, doneCh) {
if object.Err != nil {
fmt.Println(object.Err)
return
}
arr = append(arr, object)
}
var wg sync.WaitGroup
for index := range arr {
wg.Add(1)
go func(index int) {
defer wg.Done()
err = s3Client.RemoveObject(myBucket, arr[index].Key)
if err != nil {
log.Fatalln(err)
}
log.Println("Success", arr[index].Key)
} (index)
}
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.