s3fs

package module
v0.0.0-...-ac89030 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2019 License: MIT Imports: 11 Imported by: 1

README

go-s3fs

Build Status codecov Go Report Card codebeat badge GitHub

Amazon S3 wrapper for human

Overview

AWS offers a complex and bizarre SDK. We needed a library that would make it easier and faster to use S3.
go-s3fs solves this problem. It wraps the official SDK, making S3 extremely easy to use.

Installation

go get -u github.com/mobilusoss/go-s3fs

Usage

Connect to S3 using IAM role
package main

import (
	"fmt"
	"github.com/mobilusoss/go-s3fs"
)

func main() {
	fs := s3fs.New(&s3fs.Config{
		Bucket: "samplebucket",
	})
	readCloser, err := fs.Get("/file.txt")
	if err != nil {
		panic("s3 error")
	}
	buf := new(bytes.Buffer)
	if _, err := buf.ReadFrom(*readCloser); err != nil {
		panic("io error")
	}
	text := buf.String()
	fmt.Println(text)
}
Connect to MinIO
package main

import (
	"fmt"
	"github.com/mobilusoss/go-s3fs"
)

func main() {
	fs := s3fs.New(&s3fs.Config{
		Bucket: "samplebucket",
		EnableMinioCompat: true,
		Endpoint: "http://127.0.0.1:9000",
		EnableIAMAuth: true,
		AccessKeyID: "accesskey",
		AccessSecretKey: "secretkey",
	})
	readCloser, err := fs.Get("/file.txt")
	if err != nil {
		panic("s3 error")
	}
	buf := new(bytes.Buffer)
	if _, err := buf.ReadFrom(*readCloser); err != nil {
		panic("io error")
	}
	text := buf.String()
	fmt.Println(text)
}
Can be logically divided tenant
package main

import (
	"github.com/mobilusoss/go-s3fs"
)

func main() {
	_ = s3fs.New(&s3fs.Config{
		Bucket: "samplebucket",
		Domain: "tenantone",
	})
}
Can be logically divided tenant per application
package main

import (
	"github.com/mobilusoss/go-s3fs"
)

func main() {
	_ = s3fs.New(&s3fs.Config{
		Bucket: "samplebucket",
		Namespace: "appone",
		Domain: "tenantone",
	})
}

License

MIT

Documentation

Index

Constants

View Source
const (
	Directory int = 1 + iota
	File
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	NameSpace         string
	Domain            string
	Region            string
	Bucket            string
	EnableIAMAuth     bool
	AccessKeyID       string
	AccessSecretKey   string
	EnableMinioCompat bool
	Endpoint          string
}

type CopyInfo

type CopyInfo struct {
	Src  string
	Dest string
}

type FileInfo

type FileInfo struct {
	Name string `json:"name"`
	Path string `json:"path"`
	Type int    `json:"type"`
	Size int64  `json:"size,omitempty"`
}

type S3FS

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

func New

func New(config *Config) *S3FS

func (*S3FS) BulkCopy

func (this *S3FS) BulkCopy(prefix string, dest string, metadata *map[string]*string) error

func (*S3FS) BulkDelete

func (this *S3FS) BulkDelete(prefix string) error

func (*S3FS) BulkMove

func (this *S3FS) BulkMove(prefix string, dest string) error

func (*S3FS) Copy

func (this *S3FS) Copy(src string, dest string, metadata *map[string]*string) error

func (*S3FS) CreateBucket

func (this *S3FS) CreateBucket(name string) error

func (*S3FS) Delete

func (this *S3FS) Delete(key string) error

func (*S3FS) DeleteBucket

func (this *S3FS) DeleteBucket(name string) error

func (*S3FS) ExactPathExists

func (this *S3FS) ExactPathExists(key string) bool

func (*S3FS) Get

func (this *S3FS) Get(key string) (*io.ReadCloser, error)

func (*S3FS) Info

func (this *S3FS) Info(key string) *s3.HeadObjectOutput

func (*S3FS) List

func (this *S3FS) List(key string) *[]FileInfo

func (*S3FS) MkDir

func (this *S3FS) MkDir(key string) error

func (*S3FS) Move

func (this *S3FS) Move(src string, dest string) error

func (*S3FS) PathExists

func (this *S3FS) PathExists(key string) bool

func (*S3FS) Put

func (this *S3FS) Put(key string, body io.ReadCloser, contentType string) error

func (*S3FS) SingleCopy

func (this *S3FS) SingleCopy(src string, dest string, metadata *map[string]*string) error

func (*S3FS) SingleDelete

func (this *S3FS) SingleDelete(key string) error

func (*S3FS) SingleMove

func (this *S3FS) SingleMove(src string, dest string) error

Jump to

Keyboard shortcuts

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