https://github.com/d5/go-s3fs
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/d5/go-s3fs
- Owner: d5
- License: mit
- Created: 2018-12-05T06:40:49.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-05T06:50:36.000Z (over 7 years ago)
- Last Synced: 2025-03-18T07:26:42.622Z (over 1 year ago)
- Language: Go
- Size: 12.7 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# s3fs
[](https://godoc.org/github.com/d5/go-s3fs)
A simple S3-based file store implementation for Go.
Example:
```go
package main
import (
"fmt"
"os"
"time"
"github.com/d5/go-s3fs"
)
func main() {
// create client
client := s3fs.NewClient(
os.Getenv("S3_BUCKET"), // S3 bucket name
nil, // use default client options
s3fs.NewAWSSession(), // AWS session
s3fs.NewAWSConfigWithStaticCredentialsAndRegion(
os.Getenv("AWS_ACCESS_KEY_ID"), // AWS access key
os.Getenv("AWS_SECRET_ACCESS_KEY"), // AWS secret key
os.Getenv("S3_BUCKET_REGION"))) // S3 bucket region
// write a file
err := client.Write(&s3fs.File{
Path: "test/foo/bar",
Data: []byte("hello world!"),
ContentType: s3fs.StringPtr("text/plain"),
})
if err != nil {
panic(err)
}
// read a file
file, err := client.Read("test/foo/bar")
if err != nil {
panic(err)
}
fmt.Println(string(file.Data))
// get a pre-signed URL for the file
link, err := client.GenerateURLWithExpire("test/foo/bar", 10*time.Minute)
if err != nil {
panic(err)
}
fmt.Println(link)
}
```
To run tests, you need to create your own S3 bucket and set the following environment variables.
```bash
export AWS_ACCESS_KEY_ID=""
export AWS_SECRET_ACCESS_KEY=""
export TEST_S3_BUCKET=""
export TEST_S3_BUCKET_REGION=""
# run tests
make test
```