本文整理匯總了Golang中github.com/aws/aws-sdk-go/service/s3.S3.ListObjectsPages方法的典型用法代碼示例。如果您正苦於以下問題:Golang S3.ListObjectsPages方法的具體用法?Golang S3.ListObjectsPages怎麽用?Golang S3.ListObjectsPages使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/aws/aws-sdk-go/service/s3.S3
的用法示例。
在下文中一共展示了S3.ListObjectsPages方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: LatestLogFilesList
func LatestLogFilesList(client *s3.S3, downloader *s3manager.Downloader, numLogs int) ([]string, error) {
params := &s3.ListObjectsInput{
Bucket: aws.String("lattice-logs"),
MaxKeys: aws.Int64(1<<31 - 1),
Prefix: aws.String("logs/"),
}
logFiles := []string{}
err := client.ListObjectsPages(params, func(page *s3.ListObjectsOutput, lastPage bool) bool {
for _, o := range page.Contents {
logFiles = append(logFiles, *o.Key)
}
return true
})
if err != nil {
return []string{}, err
}
return logFiles[len(logFiles)-numLogs-1 : len(logFiles)-1], nil
}
示例2: ListS3Objects
// ListS3Objects returns all object keys matching the given prefix. Note that
// delimiter is set to "/". See http://docs.aws.amazon.com/AmazonS3/latest/dev/ListingKeysHierarchy.html
func ListS3Objects(client *s3.S3, bucket, keyPrefix string) ([]string, error) {
logger.Debug("ListS3Objects: ", bucket, "-", keyPrefix)
params := &s3.ListObjectsInput{
Bucket: aws.String(bucket), // Required
Delimiter: aws.String("/"),
// EncodingType: aws.String("EncodingType"),
// Marker: aws.String("Marker"),
MaxKeys: aws.Int64(1000),
Prefix: aws.String(keyPrefix),
}
objects := []string{}
err := client.ListObjectsPages(params, func(page *s3.ListObjectsOutput, lastPage bool) bool {
for _, o := range page.Contents {
objects = append(objects, *o.Key)
}
return lastPage
})
if err != nil {
return nil, err
}
return objects, nil
}