Created
March 18, 2016 10:16
-
-
Save Rauk/457be89a59c33220ab30 to your computer and use it in GitHub Desktop.
Delete All the objects in the bucket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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