Example #1
0
func bucketWalker(s *s3.S3, name, prefix, marker string) {
	bucket := s.Bucket(name)

	// list out bucket contents
	list, err := bucket.List(prefix, "/", marker, 1000)
	if err != nil {
		log.Println(err.Error())
		return
	}

	// append any files to items
	if len(list.Contents) > 0 {
		for _, k := range list.Contents {
			items = append(items, k)
		}

		if list.IsTruncated {
			last := items[len(items)-1]
			bucketWalker(s, name, prefix, last.Key)
		}
	}

	// recurse over each folder
	if len(list.CommonPrefixes) > 0 {
		for _, p := range list.CommonPrefixes {
			bucketWalker(s, name, p, "")
		}
	} else {
		return
	}
}
Example #2
0
func testBucket(s *s3.S3) *s3.Bucket {
	// Watch out! If this function is corrupted and made to match with something
	// people own, killBucket will happily remove *everything* inside the bucket.
	key := s.Auth.AccessKey
	if len(key) >= 8 {
		key = s.Auth.AccessKey[:8]
	}
	return s.Bucket(fmt.Sprintf("goamz-%s-%s", s.Region.Name, key))
}