本文整理汇总了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
}