Skip to content

mobilusoss/go-s3fs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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