本文整理匯總了Golang中github.com/crowdmob/goamz/s3.Bucket.Exists方法的典型用法代碼示例。如果您正苦於以下問題:Golang Bucket.Exists方法的具體用法?Golang Bucket.Exists怎麽用?Golang Bucket.Exists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/crowdmob/goamz/s3.Bucket
的用法示例。
在下文中一共展示了Bucket.Exists方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: StoreToS3AndRelease
func (chunkBuffer *ChunkBuffer) StoreToS3AndRelease(s3bucket *s3.Bucket) (bool, error) {
var s3path string
var err error
if debug {
fmt.Printf("Closing bufferfile: %s\n", chunkBuffer.File.Name())
}
chunkBuffer.File.Close()
contents, err := ioutil.ReadFile(chunkBuffer.File.Name())
if err != nil {
return false, err
}
if len(contents) <= 0 {
if debug {
fmt.Printf("Nothing to store to s3 for bufferfile: %s\n", chunkBuffer.File.Name())
}
} else { // Write to s3 in a new filename
alreadyExists := true
for alreadyExists {
writeTime := time.Now()
s3path = fmt.Sprintf("%s%s%d", S3TopicPartitionPrefix(chunkBuffer.Topic, chunkBuffer.Partition), S3DatePrefix(&writeTime), writeTime.UnixNano())
alreadyExists, err = s3bucket.Exists(s3path)
if err != nil {
panic(err)
return false, err
}
}
fmt.Printf("S3 Put Object: { Bucket: %s, Key: %s, MimeType:%s }\n", s3bucket.Name, s3path, mime.TypeByExtension(filepath.Ext(chunkBuffer.File.Name())))
err = s3bucket.Put(s3path, contents, mime.TypeByExtension(filepath.Ext(chunkBuffer.File.Name())), s3.Private, s3.Options{})
if err != nil {
panic(err)
}
}
if !keepBufferFiles {
if debug {
fmt.Printf("Deleting bufferfile: %s\n", chunkBuffer.File.Name())
}
err = os.Remove(chunkBuffer.File.Name())
if err != nil {
fmt.Errorf("Error deleting bufferfile %s: %#v", chunkBuffer.File.Name(), err)
}
}
return true, nil
}