From e7e2a17fec70f3dd5a664b229db23ae015ac54dd Mon Sep 17 00:00:00 2001 From: thisisaaronland Date: Wed, 3 Jun 2020 15:48:19 -0700 Subject: [PATCH] update to reflect changes in go-writer v0.2.0 --- go.mod | 2 +- go.sum | 2 ++ writer.go | 41 +++++++++++++---------------------------- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/go.mod b/go.mod index f8eae38..cb6a1bb 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module github.com/whosonfirst/go-writer-blob go 1.12 require ( - github.com/whosonfirst/go-writer v0.1.0 + github.com/whosonfirst/go-writer v0.2.0 gocloud.dev v0.19.0 ) diff --git a/go.sum b/go.sum index ff695a6..26ad67a 100644 --- a/go.sum +++ b/go.sum @@ -124,6 +124,8 @@ github.com/whosonfirst/go-writer v0.0.2 h1:ZWPMCUyQS8Khvyhz34iAsEhvRFFWo5JvraQOU github.com/whosonfirst/go-writer v0.0.2/go.mod h1:icuZIaxlsSAb8TnAzZFYt2G4ObYeI3vBmcNRimB92sY= github.com/whosonfirst/go-writer v0.1.0 h1:TAb2++rpGcxlqvtCMMTuBzb3PXFQzGobpFB62WUPfQU= github.com/whosonfirst/go-writer v0.1.0/go.mod h1:NGPaud/M3Q6IKLDj2X0PbKKpfWRF9Zneups/BMCG0+0= +github.com/whosonfirst/go-writer v0.2.0 h1:3RCym51cVwbhTpAZ7XKoWsXcodbEbKGDWYUpHoXyEOQ= +github.com/whosonfirst/go-writer v0.2.0/go.mod h1:NGPaud/M3Q6IKLDj2X0PbKKpfWRF9Zneups/BMCG0+0= go.opencensus.io v0.15.0/go.mod h1:UffZAU+4sDEINUGP/B7UfBBkq4fqLu9zXAX7ke6CHW0= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0 h1:C9hSCOW830chIVkdja34wa6Ky+IzWllkUinR+BtRZd4= diff --git a/writer.go b/writer.go index 4c8fca5..227b7c5 100644 --- a/writer.go +++ b/writer.go @@ -7,13 +7,20 @@ import ( "io" ) +type BlobWriterOptionsKey string + +type BlobWriter struct { + wof_writer.Writer + bucket *blob.Bucket +} + func init() { ctx := context.Background() for _, scheme := range blob.DefaultURLMux().BucketSchemes() { - err := wof_writer.RegisterWriter(ctx, scheme, initializeBlobWriter) + err := wof_writer.RegisterWriter(ctx, scheme, NewBlobWriter) if err != nil { panic(err) @@ -21,41 +28,19 @@ func init() { } } -func initializeBlobWriter(ctx context.Context, uri string) (wof_writer.Writer, error) { +func NewBlobWriter(ctx context.Context, uri string) (wof_writer.Writer, error) { - wr := NewBlobWriter() - err := wr.Open(ctx, uri) + bucket, err := blob.OpenBucket(ctx, uri) if err != nil { return nil, err } - return wr, nil -} - -type BlobWriterOptionsKey string - -type BlobWriter struct { - wof_writer.Writer - bucket *blob.Bucket -} - -func NewBlobWriter() wof_writer.Writer { - - wr := BlobWriter{} - return &wr -} - -func (wr *BlobWriter) Open(ctx context.Context, uri string) error { - - bucket, err := blob.OpenBucket(ctx, uri) - - if err != nil { - return err + wr := &BlobWriter{ + bucket: bucket, } - wr.bucket = bucket - return nil + return wr, nil } func (wr *BlobWriter) Write(ctx context.Context, uri string, fh io.ReadCloser) error {