maleominio

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Wrap

func Wrap(client *minio.Client, bucketName string, options ...WrapOption) bucket.Bucket

Wrap wraps minio client to Maleo bucket implementation.

Client credentials must have permission to write access to target bucket.

If client has permission to list and create bucket, it will be used to check if bucket is not exist on initialization, and create the bucket if it is not exist. If client does not have such permissions, it will be silently ignored.

You may operate how bucket creation and put object operation is executed by providing options.

Example
client, err := minio.New("play.min.io", &minio.Options{
	Creds:  credentials.NewStaticV4("access_key", "secret_key", ""),
	Secure: true,
})
if err != nil {
	fmt.Println(err.Error())
	return
}
bkt := maleominio.Wrap(client, "my-bucket")
f := strings.NewReader("hello world")
file := bucket.NewFile(f, "text/plain; charset=utf-8")
for _, result := range bkt.Upload(context.Background(), []bucket.File{file}) {
	if result.Error != nil {
		fmt.Println(result.Error.Error())
		return
	}
}
Output:

Example (Aws)
// Note the region. It's mandatory.
client, err := minio.New("s3.us-east-1.amazonaws.com", &minio.Options{
	Creds:  credentials.NewStaticV4("access_key", "secret_key", ""),
	Secure: true,
})
if err != nil {
	fmt.Println(err.Error())
	return
}
bkt := maleominio.Wrap(client, "my-bucket",
	// add optional "yyyy-mm-dd" folder to all uploaded files.
	maleominio.WithFilePrefixStringer(
		maleominio.StringerFunc(func() string {
			return time.Now().Format("2006-01-02/")
		}),
	),
)
f := strings.NewReader("hello world")
file := bucket.NewFile(f, "text/plain; charset=utf-8")
for _, result := range bkt.Upload(context.Background(), []bucket.File{file}) {
	if result.Error != nil {
		fmt.Println(result.Error.Error())
		return
	}
}
Output:

Types

type Minio

type Minio struct {
	*minio.Client
	// contains filtered or unexported fields
}

func (Minio) Upload

func (m Minio) Upload(ctx context.Context, files []bucket.File) []bucket.UploadResult

type Option

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

type PutObjectOptionFunc

type PutObjectOptionFunc = func(ctx context.Context, file bucket.File) minio.PutObjectOptions

type StringerFunc

type StringerFunc func() string

func (StringerFunc) String

func (s StringerFunc) String() string

type WrapOption

type WrapOption interface {
	// contains filtered or unexported methods
}

func WithFilePrefix

func WithFilePrefix(s string) WrapOption

WithFilePrefix sets static prefix for file name.

func WithFilePrefixStringer

func WithFilePrefixStringer(s fmt.Stringer) WrapOption

WithFilePrefixStringer sets dynamic prefix for file name.

func WithMakeBucketOption

func WithMakeBucketOption(opt minio.MakeBucketOptions) WrapOption

WithMakeBucketOption sets make bucket option for Minio if bucket does not exist.

func WithPutObjectOption

func WithPutObjectOption(f PutObjectOptionFunc) WrapOption

WithPutObjectOption sets put object option for Minio.

Jump to

Keyboard shortcuts

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