Skip to content

Instantly share code, notes, and snippets.

@Rauk
Created March 18, 2016 10:16
Show Gist options
  • Save Rauk/457be89a59c33220ab30 to your computer and use it in GitHub Desktop.
Save Rauk/457be89a59c33220ab30 to your computer and use it in GitHub Desktop.
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)
}
for j, _ := range arr {
go func(j int) {
err = s3Client.RemoveObject(myBucket, arr[j].Key)
if err != nil {
log.Fatalln(err)
}
log.Println("Success", arr[j].Key)
} (j)
}
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment