monk

package module
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2022 License: MIT Imports: 10 Imported by: 0

README

monk

Documentation

Index

Constants

View Source
const (
	AwsUsEast1    = "us-east-1"
	AwsUsWest1    = "us-west-1"
	AwsEuWest1    = "eu-west-1"
	AwsEuCentral1 = "eu-central-1"
)
View Source
const (
	HTTP  = "http"
	HTTPS = "https"
	FILE  = "file"
	S3    = "s3"
)

Variables

View Source
var (
	ErrUnimplementedScheme = errors.New("monk: unimplemented scheme")
	ErrInvalidURL          = errors.New("monk: invalid url")
)
View Source
var (
	// WithMethod returns an Option that sets
	// the method of a Reader or Writer to the given string.
	WithMethod = func(m string) Option {
		return func(r *configuration) {
			r.method = m
		}
	}

	// WithHeaders returns an Option that sets
	// the headers of a Reader or Writer to the given map.
	WithHeaders = func(h map[string]string) Option {
		return func(r *configuration) {
			r.headers = h
		}
	}

	// WithHttpClient returns an Option that sets
	// the http client of a Reader or Writer  to the given http client.
	WithHttpClient = func(h *http.Client) Option {
		return func(r *configuration) {
			r.httpClient = h
		}
	}

	// WithS3ClientFunc returns an Option that sets
	// the s3 client generation function of a Reader or Writer.
	//
	// This function is called before every invocation to s3,
	// handling the connection pooling is upto the implementation.
	//
	// The default implementation uses the default configuration
	// to create the client and uses the same client for every call.
	WithS3ClientFunc = func(s3ClientFunc S3ClientFunc) Option {
		return func(r *configuration) {
			r.s3ClientFn = s3ClientFunc
		}
	}

	// WithContext returns a Option that configures a Reader or Writer
	// to carry out the read operation abiding to the provided context.
	//
	// For HTTP and s3 requests the context is used during request
	// and client initializations respectively.
	//
	// For filesystem reads if the context has a deadline the value
	// is used to set the ReadDeadline of a file, if the context has no
	// deadline, it is discarded.
	//
	// If unset context is context.Background()
	WithContext = func(ctx context.Context) Option {
		return func(r *configuration) {
			r.ctx = ctx
		}
	}
)

Functions

func Read

func Read(l string, options ...ReaderOption) ([]byte, error)

func Write

func Write(data []byte, l string, options ...WriterOption) error

Types

type Option

type Option func(*configuration)

func (Option) ConfigureReader

func (o Option) ConfigureReader(r *Reader)

func (Option) ConfigureWriter

func (o Option) ConfigureWriter(w *Writer)

type ReadHandler

type ReadHandler struct {
	Scheme string
	Fn     func(*Reader) ([]byte, error)
}

ReadHandler carries out a Read operation for a specific protocol, configuring itself based on the given Reader. Handlers attempt to take as much Reader options as possible into account when carrying out the operation but can ignore them if they are not applicable in the context of the protocol.

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

func NewReader

func NewReader(l string, opts ...ReaderOption) *Reader

func (*Reader) Read

func (r *Reader) Read(b []byte) (n int, err error)

type ReaderOption

type ReaderOption interface {
	ConfigureReader(r *Reader)
}

type S3ClientFunc

type S3ClientFunc func(ctx context.Context) (S3ReadWriter, error)

type S3ReadWriter

type S3ReadWriter interface {
	S3Reader
	S3Writer
}

type S3Reader

type S3Reader interface {
	GetObject(
		ctx context.Context,
		input *s3.GetObjectInput,
		opts ...func(*s3.Options),
	) (*s3.GetObjectOutput, error)
}

type S3Writer

type S3Writer interface {
	PutObject(
		ctx context.Context,
		input *s3.PutObjectInput,
		opts ...func(*s3.Options),
	) (*s3.PutObjectOutput, error)
}

type WriteHandler

type WriteHandler struct {
	Scheme string
	Fn     func(*Writer) error
}

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

func NewWriter

func NewWriter(l string, opts ...WriterOption) *Writer

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

type WriterOption

type WriterOption interface {
	ConfigureWriter(w *Writer)
}

Jump to

Keyboard shortcuts

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