Skip to content

Commit

Permalink
update to reflect changes in go-writer v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisaaronland committed Jun 3, 2020
1 parent de3cd31 commit e7e2a17
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 29 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
41 changes: 13 additions & 28 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,40 @@ 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)
}
}
}

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 {
Expand Down

0 comments on commit e7e2a17

Please sign in to comment.