Documentation ¶
Overview ¶
Package gcsbucket provides an implementation of Bucket for Google Cloud Storage.
Example ¶
package main import ( "context" "fmt" "io/ioutil" "log" "strings" "github.com/fishy/gcsbucket" ) func main() { ctx := context.Background() bkt, err := gcsbucket.Open(ctx, "test-bucket") if err != nil { // TODO: error handling } 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.` 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) } fmt.Println(bkt.IsNotExist(bkt.Delete(ctx, obj))) // true }
Output:
Index ¶
- type GCSBucket
- func (gcs *GCSBucket) Close() error
- func (gcs *GCSBucket) Delete(ctx context.Context, name string) error
- func (gcs *GCSBucket) IsNotExist(err error) bool
- func (gcs *GCSBucket) Read(ctx context.Context, name string) (io.ReadCloser, error)
- func (gcs *GCSBucket) Write(ctx context.Context, name string, data io.Reader) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GCSBucket ¶
type GCSBucket struct {
// contains filtered or unexported fields
}
GCSBucket is an implementation of bucket with Google Cloud Storage.
func Open ¶
Open opens a gcs bucket.
The bucket must already exist, otherwise all operations will fail.
func (*GCSBucket) Close ¶
Close releases resources associated with this bucket.
All operations will panic after Close is called.
Close need not be called at program exit.
func (*GCSBucket) IsNotExist ¶
IsNotExist checks whether err is storage.ErrObjectNotExist.
Click to show internal directories.
Click to hide internal directories.