當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Bucket.List方法代碼示例

本文整理匯總了Golang中github.com/crowdmob/goamz/s3.Bucket.List方法的典型用法代碼示例。如果您正苦於以下問題:Golang Bucket.List方法的具體用法?Golang Bucket.List怎麽用?Golang Bucket.List使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/crowdmob/goamz/s3.Bucket的用法示例。


在下文中一共展示了Bucket.List方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: killBucket

func killBucket(b *s3.Bucket) {
	var err error
	for attempt := attempts.Start(); attempt.Next(); {
		err = b.DelBucket()
		if err == nil {
			return
		}
		if _, ok := err.(*net.DNSError); ok {
			return
		}
		e, ok := err.(*s3.Error)
		if ok && e.Code == "NoSuchBucket" {
			return
		}
		if ok && e.Code == "BucketNotEmpty" {
			// Errors are ignored here. Just retry.
			resp, err := b.List("", "", "", 1000)
			if err == nil {
				for _, key := range resp.Contents {
					_ = b.Del(key.Key)
				}
			}
			multis, _, _ := b.ListMulti("", "")
			for _, m := range multis {
				_ = m.Abort()
			}
		}
	}
	message := "cannot delete test bucket"
	if err != nil {
		message += ": " + err.Error()
	}
	panic(message)
}
開發者ID:number9code,項目名稱:dogestry,代碼行數:34,代碼來源:s3i_test.go

示例2: listFiles

// listFiles lists the files in a specific s3 bucket.
func listFiles(prefix, delimiter, marker string, maxKeys int, b *s3.Bucket) (files []s3.Key, err error) {
	resp, err := b.List(prefix, delimiter, marker, maxKeys)
	if err != nil {
		return nil, err
	}

	// append to files
	for _, fl := range resp.Contents {
		if strings.Contains(fl.Key, "index.html") || strings.Contains(fl.Key, "static") || strings.Contains(fl.Key, "logs") {
			continue
		}

		files = append(files, fl)
	}

	// recursion for the recursion god
	if resp.IsTruncated && resp.NextMarker != "" {
		f, err := listFiles(resp.Prefix, resp.Delimiter, resp.NextMarker, resp.MaxKeys, b)
		if err != nil {
			return nil, err
		}

		// append to files
		files = append(files, f...)
	}

	return files, nil
}
開發者ID:carriercomm,項目名稱:docker-bb,代碼行數:29,代碼來源:s3_utils.go

示例3: LastS3KeyWithPrefix

func LastS3KeyWithPrefix(bucket *s3.Bucket, prefix *string) (string, error) {
	narrowedPrefix := *prefix
	keyMarker := ""

	// First, do a few checks for shortcuts for checking backwards: focus in on the 14 days.
	// Otherwise just loop forward until there aren't any more results
	currentDay := time.Now()
	for i := 0; i < S3_REWIND_IN_DAYS_BEFORE_LONG_LOOP; i++ {
		testPrefix := fmt.Sprintf("%s%s", *prefix, S3DatePrefix(&currentDay))
		results, err := bucket.List(narrowedPrefix, "", keyMarker, 0)
		if err != nil && len(results.Contents) > 0 {
			narrowedPrefix = testPrefix
			break
		}
		currentDay = currentDay.Add(-1 * time.Duration(DAY_IN_SECONDS) * time.Second)
	}

	lastKey := ""
	moreResults := true
	for moreResults {
		results, err := bucket.List(narrowedPrefix, "", keyMarker, 0)
		if err != nil {
			return lastKey, err
		}

		if len(results.Contents) == 0 { // empty request, return last found lastKey
			return lastKey, nil
		}

		lastKey = results.Contents[len(results.Contents)-1].Key
		keyMarker = lastKey
		moreResults = results.IsTruncated
	}
	return lastKey, nil
}
開發者ID:hadesbox,項目名稱:kafka-s3-consumer,代碼行數:35,代碼來源:consumer.go

示例4: getS3FileHash

func getS3FileHash(bucket *s3.Bucket, filePath string) (string, error) {

	list, err := bucket.List(filePath, "", "", 1)
	if err != nil {
		return "", err
	}

	if len(list.Contents) < 1 {
		return "", ErrFileDoesNotExistS3
	}

	md5sum := strings.Trim(list.Contents[0].ETag, "\"")

	return md5sum, nil

}
開發者ID:rem7,項目名稱:s3sync,代碼行數:16,代碼來源:s3sync.go


注:本文中的github.com/crowdmob/goamz/s3.Bucket.List方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。