Go client SDK for libreFS and any Amazon S3-compatible object storage. Forked from minio/minio-go.
For a complete list of APIs and examples, see the godoc documentation.
These examples assume a working Go development environment and the lc CLI tool.
From your project directory:
go get github.com/libreFS/librefs-go/v7| Parameter | Description |
|---|---|
endpoint |
URL to object storage service. |
minio.Options |
All the options such as credentials, custom transport etc. |
package main
import (
"log"
"github.com/libreFS/librefs-go/v7"
"github.com/libreFS/librefs-go/v7/pkg/credentials"
)
func main() {
endpoint := "localhost:9000"
accessKeyID := "YOUR-ACCESSKEYID"
secretAccessKey := "YOUR-SECRETKEY"
useSSL := false
// Initialize S3 client object.
s3Client, err := minio.New(endpoint, &minio.Options{
Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
Secure: useSSL,
})
if err != nil {
log.Fatalln(err)
}
log.Printf("%#v\n", s3Client) // s3Client is now set up
}This sample code connects to a libreFS server, creates a bucket, and uploads a file.
package main
import (
"context"
"log"
"github.com/libreFS/librefs-go/v7"
"github.com/libreFS/librefs-go/v7/pkg/credentials"
)
func main() {
ctx := context.Background()
endpoint := "localhost:9000"
accessKeyID := "YOUR-ACCESSKEYID"
secretAccessKey := "YOUR-SECRETKEY"
useSSL := false
// Initialize S3 client object.
s3Client, err := minio.New(endpoint, &minio.Options{
Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
Secure: useSSL,
})
if err != nil {
log.Fatalln(err)
}
bucketName := "testbucket"
location := "us-east-1"
err = s3Client.MakeBucket(ctx, bucketName, minio.MakeBucketOptions{Region: location})
if err != nil {
exists, errBucketExists := s3Client.BucketExists(ctx, bucketName)
if errBucketExists == nil && exists {
log.Printf("We already own %s\n", bucketName)
} else {
log.Fatalln(err)
}
} else {
log.Printf("Successfully created %s\n", bucketName)
}
objectName := "testdata"
filePath := "/tmp/testdata"
contentType := "application/octet-stream"
info, err := s3Client.FPutObject(ctx, bucketName, objectName, filePath, minio.PutObjectOptions{ContentType: contentType})
if err != nil {
log.Fatalln(err)
}
log.Printf("Successfully uploaded %s of size %d\n", objectName, info.Size)
}1. Create a test file:
dd if=/dev/urandom of=/tmp/testdata bs=2048 count=102. Run FileUploader:
go mod init example/FileUploader
go get github.com/libreFS/librefs-go/v7
go get github.com/libreFS/librefs-go/v7/pkg/credentials
go run FileUploader.go3. Verify with lc ls:
lc ls myserver/testbucketFull API reference: pkg.go.dev/github.com/libreFS/librefs-go/v7
SetBucketNotificationGetBucketNotificationRemoveAllBucketNotificationListenBucketNotificationListenNotification
See the examples/ directory.
See CONTRIBUTING.md.
Distributed under the Apache License, Version 2.0 — see LICENSE and NOTICE.