Skip to content

libreFS/librefs-go

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1,920 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

librefs-go — libreFS S3 Go SDK

Apache V2 License

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.

Install

From your project directory:

go get github.com/libreFS/librefs-go/v7

Initialize a Client Object

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
}

Example - File Uploader

This sample code connects to a libreFS server, creates a bucket, and uploads a file.

FileUploader.go

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=10

2. 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.go

3. Verify with lc ls:

lc ls myserver/testbucket

API Reference

Full API reference: pkg.go.dev/github.com/libreFS/librefs-go/v7

Bucket Operations

Bucket Policy Operations

Bucket Notification Operations

File Object Operations

Object Operations

Presigned Operations

Client Settings

Full Examples

See the examples/ directory.

Contribute

See CONTRIBUTING.md.

License

Distributed under the Apache License, Version 2.0 — see LICENSE and NOTICE.

About

MinIO Go client SDK for S3 compatible object storage

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Go 99.9%
  • Makefile 0.1%