The Minio Golang Client SDK provides simple APIs to access any Amazon S3 compatible object storage server.
Supported cloud storage providers:
-
AWS Signature Version 4
- Amazon S3
- Minio
-
AWS Signature Version 2
- Google Cloud Storage (Compatibility Mode)
- Openstack Swift + Swift3 middleware
- Ceph Object Gateway
- Riak CS
This quickstart guide will show you how to install the Minio client SDK, connect to Minio, and provide a walkthrough of a simple file uploader. For a complete list of APIs and examples, please take a look at the Golang Client API Reference.
This document assumes that you have a working Golang setup.
$ go get -u github.com/minio/minio-go
You need four items to connect to Minio object storage server.
Parameter | Description |
---|---|
endpoint | URL to object storage service. |
accessKeyID | Access key is the user ID that uniquely identifies your account. |
secretAccessKey | Secret key is the password to your account. |
secure | Set this value to 'true' to enable secure (HTTPS) access. |
package main
import (
"github.com/minio/minio-go"
"log"
)
func main() {
endpoint := "play.minio.io:9000"
accessKeyID := "Q3AM3UQ867SPQQA43P2F"
secretAccessKey := "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
useSSL := true
// Initialize minio client object.
minioClient, err := minio.New(endpoint, accessKeyID, secretAccessKey, useSSL)
if err != nil {
log.Fatalln(err)
}
log.Println("%v", minioClient) // minioClient is now setup
This example program connects to an object storage server, makes a bucket on the server and then uploads a file to the bucket.
We will use the Minio server running at https://play.minio.io:9000 in this example. Feel free to use this service for testing and development. Access credentials shown in this example are open to the public.
package main
import (
"github.com/minio/minio-go"
"log"
)
func main() {
endpoint := "play.minio.io:9000"
accessKeyID := "Q3AM3UQ867SPQQA43P2F"
secretAccessKey := "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
useSSL := true
// Initialize minio client object.
minioClient, err := minio.New(endpoint, accessKeyID, secretAccessKey, useSSL)
if err != nil {
log.Fatalln(err)
}
// Make a new bucked called mymusic.
bucketName := "mymusic"
location := "us-east-1"
err = minioClient.MakeBucket(bucketName, location)
if err != nil {
// Check to see if we already own this bucket (which happens if you run this twice)
exists, err := minioClient.BucketExists(bucketName)
if err == nil && exists {
log.Printf("We already own %s\n", bucketName)
} else {
log.Fatalln(err)
}
}
log.Printf("Successfully created %s\n", bucketName)
// Upload the zip file
objectName := "golden-oldies.zip"
filePath := "/tmp/golden-oldies.zip"
contentType := "application/zip"
// Upload the zip file with FPutObject
n, err := minioClient.FPutObject(bucketName, objectName, filePath, contentType)
if err != nil {
log.Fatalln(err)
}
log.Printf("Successfully uploaded %s of size %d\n", objectName, n)
}
$ go run file-uploader.go
2016/08/13 17:03:28 Successfully created mymusic
2016/08/13 17:03:40 Successfully uploaded golden-oldies.zip of size 16253413
$ mc ls play/mymusic/
[2016-05-27 16:02:16 PDT] 17MiB golden-oldies.zip
The full API Reference is available here.
SetBucketNotification
GetBucketNotification
RemoveAllBucketNotification
ListenBucketNotification
(Minio Extension)
- listbuckets.go
- listobjects.go
- bucketexists.go
- makebucket.go
- removebucket.go
- listincompleteuploads.go
- setbucketnotification.go
- getbucketnotification.go
- deletebucketnotification.go
- listenbucketnotification.go (Minio Extension)