writer

package module
v3.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

README

go-writer-blob

Go Cloud Blob support for the go-writer Writer interface.

Work in progress. This will replace go-whosonfirst-readwrite.

Example

package main

import (
	"bytes"
	"errors"
	"context"
	"github.com/whosonfirst/go-writer"
	_ "github.com/aaronland/go-cloud-s3blob"	
	blob_writer "github.com/whosonfirst/go-writer-blob/v3"
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/service/s3/s3manager"	
	gc_blob "gocloud.dev/blob"	
	"io/ioutil"
)

func main() {

	bucket := "s3-bucket"
	region := "s3-region"
	
	blob_uri := fmt.Sprintf("s3blob://%s?region=%s&credentials=session", bucket, region)
	
	ctx := context.Background()
	wr, _ := writer.NewWriter(ctx, blob_uri)
	
	br := bytes.NewReader([]byte("hello"))
	fh := ioutil.NopCloser(br)

	before := func(asFunc func(interface{}) bool) error {
		
		req := &s3manager.UploadInput{}
		ok := asFunc(&req)
		
		if !ok {
			return errors.New("invalid s3 type")
		}
		
		req.ACL = aws.String("public-read")
		return nil
	}
	
	wr_opts := &gc_blob.WriterOptions{
		BeforeWrite: before,
	}

	ctx = context.WithValue(ctx, blob_writer.BlobWriterOptionsKey("options"), wr_opts)
	
	wr.Write(ctx, "test.txt", fh)
}

See also

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBlobWriter

func NewBlobWriter(ctx context.Context, uri string) (wof_writer.Writer, error)

func RegisterSchemes added in v3.0.4

func RegisterSchemes(ctx context.Context) error

RegisterSchemes will explicitly register all the schemes associated with the `AccessTokensDeliveryAgent` interface.

Types

type BlobWriter

type BlobWriter struct {
	wof_writer.Writer
	// contains filtered or unexported fields
}

func (*BlobWriter) Close

func (wr *BlobWriter) Close(ctx context.Context) error

func (*BlobWriter) Flush

func (wr *BlobWriter) Flush(ctx context.Context) error

func (*BlobWriter) SetLogger

func (wr *BlobWriter) SetLogger(ctx context.Context, logger *log.Logger) error

func (*BlobWriter) Write

func (wr *BlobWriter) Write(ctx context.Context, uri string, fh io.ReadSeeker) (int64, error)

func (*BlobWriter) WriterURI

func (wr *BlobWriter) WriterURI(ctx context.Context, uri string) string

type BlobWriterOptionsKey

type BlobWriterOptionsKey string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL