Documentation ¶
Overview ¶
Package s3bucket provides an implementation of Bucket for AWS S3.
Example ¶
package main import ( "context" "fmt" "io/ioutil" "log" "strings" "github.com/fishy/s3bucket" ) func main() { ctx := context.Background() region := "us-east-1" bkt := s3bucket.Open("test-bucket", region) obj := "test/object" content := `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.` _, err := bkt.Read(ctx, obj) fmt.Println(bkt.IsNotExist(err)) // true if err := bkt.Write(ctx, obj, strings.NewReader(content)); err != nil { log.Fatal(err) } reader, err := bkt.Read(ctx, obj) if err != nil { log.Fatal(err) } defer reader.Close() buf, err := ioutil.ReadAll(reader) if err != nil { log.Fatal(err) } fmt.Println(string(buf)) // content if err := bkt.Delete(ctx, obj); err != nil { log.Fatal(err) } }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type S3Bucket ¶
type S3Bucket struct {
// contains filtered or unexported fields
}
S3Bucket is an implementation of bucket with S3.
func Open ¶
Open opens an s3 bucket.
The bucket must already exist, otherwise all operations will fail.
func (*S3Bucket) Delete ¶
Delete deletes an object from the bucket.
Please note that S3 will NOT return error when deleting a non-exist object.
func (*S3Bucket) IsNotExist ¶
IsNotExist checks whether err is an awserr.Error with code ErrCodeNoSuchKey.
Click to show internal directories.
Click to hide internal directories.