github.com/minio/minio-go/v6@v6.0.57/README.md (about)

     1  # MinIO Go Client SDK for Amazon S3 Compatible Cloud Storage [![Slack](https://slack.min.io/slack?type=svg)](https://slack.min.io) [![Sourcegraph](https://sourcegraph.com/github.com/minio/minio-go/-/badge.svg)](https://sourcegraph.com/github.com/minio/minio-go?badge) [![Apache V2 License](http://img.shields.io/badge/license-Apache%20V2-blue.svg)](https://github.com/minio/minio-go/blob/master/LICENSE)
     2  
     3  The MinIO Go Client SDK provides simple APIs to access any Amazon S3 compatible object storage.
     4  
     5  This quickstart guide will show you how to install the MinIO client SDK, connect to MinIO, and provide a walkthrough for a simple file uploader. For a complete list of APIs and examples, please take a look at the [Go Client API Reference](https://docs.min.io/docs/golang-client-api-reference).
     6  
     7  This document assumes that you have a working [Go development environment](https://golang.org/doc/install).
     8  
     9  ## Download from Github
    10  ```sh
    11  GO111MODULE=on go get github.com/minio/minio-go/v6
    12  ```
    13  
    14  ## Initialize MinIO Client
    15  MinIO client requires the following four parameters specified to connect to an Amazon S3 compatible object storage.
    16  
    17  | Parameter  | Description|
    18  | :---         |     :---     |
    19  | endpoint   | URL to object storage service.   |
    20  | accessKeyID | Access key is the user ID that uniquely identifies your account. |   
    21  | secretAccessKey | Secret key is the password to your account. |
    22  | secure | Set this value to 'true' to enable secure (HTTPS) access. |
    23  
    24  
    25  ```go
    26  package main
    27  
    28  import (
    29  	"github.com/minio/minio-go/v6"
    30  	"log"
    31  )
    32  
    33  func main() {
    34  	endpoint := "play.min.io"
    35  	accessKeyID := "Q3AM3UQ867SPQQA43P2F"
    36  	secretAccessKey := "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
    37  	useSSL := true
    38  
    39  	// Initialize minio client object.
    40  	minioClient, err := minio.New(endpoint, accessKeyID, secretAccessKey, useSSL)
    41  	if err != nil {
    42  		log.Fatalln(err)
    43  	}
    44  
    45  	log.Printf("%#v\n", minioClient) // minioClient is now setup
    46  }
    47  ```
    48  
    49  ## Quick Start Example - File Uploader
    50  This example program connects to an object storage server, creates a bucket and uploads a file to the bucket.
    51  
    52  We will use the MinIO server running at [https://play.min.io](https://play.min.io) in this example. Feel free to use this service for testing and development. Access credentials shown in this example are open to the public.
    53  
    54  ### FileUploader.go
    55  ```go
    56  package main
    57  
    58  import (
    59  	"github.com/minio/minio-go/v6"
    60  	"log"
    61  )
    62  
    63  func main() {
    64  	endpoint := "play.min.io"
    65  	accessKeyID := "Q3AM3UQ867SPQQA43P2F"
    66  	secretAccessKey := "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
    67  	useSSL := true
    68  
    69  	// Initialize minio client object.
    70  	minioClient, err := minio.New(endpoint, accessKeyID, secretAccessKey, useSSL)
    71  	if err != nil {
    72  		log.Fatalln(err)
    73  	}
    74  
    75  	// Make a new bucket called mymusic.
    76  	bucketName := "mymusic"
    77  	location := "us-east-1"
    78  
    79  	err = minioClient.MakeBucket(bucketName, location)
    80  	if err != nil {
    81  		// Check to see if we already own this bucket (which happens if you run this twice)
    82  		exists, errBucketExists := minioClient.BucketExists(bucketName)
    83  		if errBucketExists == nil && exists {
    84  			log.Printf("We already own %s\n", bucketName)
    85  		} else {
    86  			log.Fatalln(err)
    87  		}
    88  	} else {
    89  		log.Printf("Successfully created %s\n", bucketName)
    90  	}
    91  
    92  	// Upload the zip file
    93  	objectName := "golden-oldies.zip"
    94  	filePath := "/tmp/golden-oldies.zip"
    95  	contentType := "application/zip"
    96  
    97  	// Upload the zip file with FPutObject
    98  	n, err := minioClient.FPutObject(bucketName, objectName, filePath, minio.PutObjectOptions{ContentType:contentType})
    99  	if err != nil {
   100  		log.Fatalln(err)
   101  	}
   102  
   103  	log.Printf("Successfully uploaded %s of size %d\n", objectName, n)
   104  }
   105  ```
   106  
   107  ### Run FileUploader
   108  ```sh
   109  go run file-uploader.go
   110  2016/08/13 17:03:28 Successfully created mymusic
   111  2016/08/13 17:03:40 Successfully uploaded golden-oldies.zip of size 16253413
   112  
   113  mc ls play/mymusic/
   114  [2016-05-27 16:02:16 PDT]  17MiB golden-oldies.zip
   115  ```
   116  
   117  ## API Reference
   118  The full API Reference is available here.
   119  
   120  * [Complete API Reference](https://docs.min.io/docs/golang-client-api-reference)
   121  
   122  ### API Reference : Bucket Operations
   123  * [`MakeBucket`](https://docs.min.io/docs/golang-client-api-reference#MakeBucket)
   124  * [`ListBuckets`](https://docs.min.io/docs/golang-client-api-reference#ListBuckets)
   125  * [`BucketExists`](https://docs.min.io/docs/golang-client-api-reference#BucketExists)
   126  * [`RemoveBucket`](https://docs.min.io/docs/golang-client-api-reference#RemoveBucket)
   127  * [`ListObjects`](https://docs.min.io/docs/golang-client-api-reference#ListObjects)
   128  * [`ListObjectsV2`](https://docs.min.io/docs/golang-client-api-reference#ListObjectsV2)
   129  * [`ListIncompleteUploads`](https://docs.min.io/docs/golang-client-api-reference#ListIncompleteUploads)
   130  
   131  ### API Reference : Bucket policy Operations
   132  * [`SetBucketPolicy`](https://docs.min.io/docs/golang-client-api-reference#SetBucketPolicy)
   133  * [`GetBucketPolicy`](https://docs.min.io/docs/golang-client-api-reference#GetBucketPolicy)
   134  
   135  ### API Reference : Bucket notification Operations
   136  * [`SetBucketNotification`](https://docs.min.io/docs/golang-client-api-reference#SetBucketNotification)
   137  * [`GetBucketNotification`](https://docs.min.io/docs/golang-client-api-reference#GetBucketNotification)
   138  * [`RemoveAllBucketNotification`](https://docs.min.io/docs/golang-client-api-reference#RemoveAllBucketNotification)
   139  * [`ListenBucketNotification`](https://docs.min.io/docs/golang-client-api-reference#ListenBucketNotification) (MinIO Extension)
   140  
   141  ### API Reference : File Object Operations
   142  * [`FPutObject`](https://docs.min.io/docs/golang-client-api-reference#FPutObject)
   143  * [`FGetObject`](https://docs.min.io/docs/golang-client-api-reference#FGetObject)
   144  * [`FPutObjectWithContext`](https://docs.min.io/docs/golang-client-api-reference#FPutObjectWithContext)
   145  * [`FGetObjectWithContext`](https://docs.min.io/docs/golang-client-api-reference#FGetObjectWithContext)
   146  
   147  ### API Reference : Object Operations
   148  * [`GetObject`](https://docs.min.io/docs/golang-client-api-reference#GetObject)
   149  * [`PutObject`](https://docs.min.io/docs/golang-client-api-reference#PutObject)
   150  * [`GetObjectWithContext`](https://docs.min.io/docs/golang-client-api-reference#GetObjectWithContext)
   151  * [`PutObjectWithContext`](https://docs.min.io/docs/golang-client-api-reference#PutObjectWithContext)
   152  * [`PutObjectStreaming`](https://docs.min.io/docs/golang-client-api-reference#PutObjectStreaming)
   153  * [`StatObject`](https://docs.min.io/docs/golang-client-api-reference#StatObject)
   154  * [`CopyObject`](https://docs.min.io/docs/golang-client-api-reference#CopyObject)
   155  * [`RemoveObject`](https://docs.min.io/docs/golang-client-api-reference#RemoveObject)
   156  * [`RemoveObjects`](https://docs.min.io/docs/golang-client-api-reference#RemoveObjects)
   157  * [`RemoveIncompleteUpload`](https://docs.min.io/docs/golang-client-api-reference#RemoveIncompleteUpload)
   158  * [`SelectObjectContent`](https://docs.min.io/docs/golang-client-api-reference#SelectObjectContent)
   159  
   160  
   161  ### API Reference : Presigned Operations
   162  * [`PresignedGetObject`](https://docs.min.io/docs/golang-client-api-reference#PresignedGetObject)
   163  * [`PresignedPutObject`](https://docs.min.io/docs/golang-client-api-reference#PresignedPutObject)
   164  * [`PresignedHeadObject`](https://docs.min.io/docs/golang-client-api-reference#PresignedHeadObject)
   165  * [`PresignedPostPolicy`](https://docs.min.io/docs/golang-client-api-reference#PresignedPostPolicy)
   166  
   167  ### API Reference : Client custom settings
   168  * [`SetAppInfo`](http://docs.min.io/docs/golang-client-api-reference#SetAppInfo)
   169  * [`SetCustomTransport`](http://docs.min.io/docs/golang-client-api-reference#SetCustomTransport)
   170  * [`TraceOn`](http://docs.min.io/docs/golang-client-api-reference#TraceOn)
   171  * [`TraceOff`](http://docs.min.io/docs/golang-client-api-reference#TraceOff)
   172  
   173  ## Full Examples
   174  
   175  ### Full Examples : Bucket Operations
   176  * [makebucket.go](https://github.com/minio/minio-go/blob/master/examples/s3/makebucket.go)
   177  * [listbuckets.go](https://github.com/minio/minio-go/blob/master/examples/s3/listbuckets.go)
   178  * [bucketexists.go](https://github.com/minio/minio-go/blob/master/examples/s3/bucketexists.go)
   179  * [removebucket.go](https://github.com/minio/minio-go/blob/master/examples/s3/removebucket.go)
   180  * [listobjects.go](https://github.com/minio/minio-go/blob/master/examples/s3/listobjects.go)
   181  * [listobjectsV2.go](https://github.com/minio/minio-go/blob/master/examples/s3/listobjectsV2.go)
   182  * [listincompleteuploads.go](https://github.com/minio/minio-go/blob/master/examples/s3/listincompleteuploads.go)
   183  
   184  ### Full Examples : Bucket policy Operations
   185  * [setbucketpolicy.go](https://github.com/minio/minio-go/blob/master/examples/s3/setbucketpolicy.go)
   186  * [getbucketpolicy.go](https://github.com/minio/minio-go/blob/master/examples/s3/getbucketpolicy.go)
   187  * [listbucketpolicies.go](https://github.com/minio/minio-go/blob/master/examples/s3/listbucketpolicies.go)
   188  
   189  ### Full Examples : Bucket lifecycle Operations
   190  * [setbucketlifecycle.go](https://github.com/minio/minio-go/blob/master/examples/s3/setbucketlifecycle.go)
   191  * [getbucketlifecycle.go](https://github.com/minio/minio-go/blob/master/examples/s3/getbucketlifecycle.go)
   192  
   193  ### Full Examples : Bucket encryption Operations
   194  * [setbucketencryption.go](https://github.com/minio/minio-go/blob/master/examples/s3/setbucketencryption.go)
   195  * [getbucketencryption.go](https://github.com/minio/minio-go/blob/master/examples/s3/getbucketencryption.go)
   196  * [deletebucketencryption.go](https://github.com/minio/minio-go/blob/master/examples/s3/deletebucketencryption.go)
   197  
   198  ### Full Examples : Bucket notification Operations
   199  * [setbucketnotification.go](https://github.com/minio/minio-go/blob/master/examples/s3/setbucketnotification.go)
   200  * [getbucketnotification.go](https://github.com/minio/minio-go/blob/master/examples/s3/getbucketnotification.go)
   201  * [removeallbucketnotification.go](https://github.com/minio/minio-go/blob/master/examples/s3/removeallbucketnotification.go)
   202  * [listenbucketnotification.go](https://github.com/minio/minio-go/blob/master/examples/minio/listenbucketnotification.go) (MinIO Extension)
   203  
   204  ### Full Examples : File Object Operations
   205  * [fputobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/fputobject.go)
   206  * [fgetobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/fgetobject.go)
   207  * [fputobject-context.go](https://github.com/minio/minio-go/blob/master/examples/s3/fputobject-context.go)
   208  * [fgetobject-context.go](https://github.com/minio/minio-go/blob/master/examples/s3/fgetobject-context.go)
   209  
   210  ### Full Examples : Object Operations
   211  * [putobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/putobject.go)
   212  * [getobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/getobject.go)
   213  * [putobject-context.go](https://github.com/minio/minio-go/blob/master/examples/s3/putobject-context.go)
   214  * [getobject-context.go](https://github.com/minio/minio-go/blob/master/examples/s3/getobject-context.go)
   215  * [statobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/statobject.go)
   216  * [copyobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/copyobject.go)
   217  * [removeobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/removeobject.go)
   218  * [removeincompleteupload.go](https://github.com/minio/minio-go/blob/master/examples/s3/removeincompleteupload.go)
   219  * [removeobjects.go](https://github.com/minio/minio-go/blob/master/examples/s3/removeobjects.go)
   220  
   221  ### Full Examples : Encrypted Object Operations
   222  * [put-encrypted-object.go](https://github.com/minio/minio-go/blob/master/examples/s3/put-encrypted-object.go)
   223  * [get-encrypted-object.go](https://github.com/minio/minio-go/blob/master/examples/s3/get-encrypted-object.go)
   224  * [fput-encrypted-object.go](https://github.com/minio/minio-go/blob/master/examples/s3/fputencrypted-object.go)
   225  
   226  ### Full Examples : Presigned Operations
   227  * [presignedgetobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/presignedgetobject.go)
   228  * [presignedputobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/presignedputobject.go)
   229  * [presignedheadobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/presignedheadobject.go)
   230  * [presignedpostpolicy.go](https://github.com/minio/minio-go/blob/master/examples/s3/presignedpostpolicy.go)
   231  
   232  ## Explore Further
   233  * [Complete Documentation](https://docs.min.io)
   234  * [MinIO Go Client SDK API Reference](https://docs.min.io/docs/golang-client-api-reference)
   235  
   236  ## Contribute
   237  [Contributors Guide](https://github.com/minio/minio-go/blob/master/CONTRIBUTING.md)
   238  
   239  [![Build Status](https://travis-ci.org/minio/minio-go.svg)](https://travis-ci.org/minio/minio-go)
   240  [![Build status](https://ci.appveyor.com/api/projects/status/1d05e6nvxcelmrak?svg=true)](https://ci.appveyor.com/project/harshavardhana/minio-go)
   241  
   242  ## License
   243  This SDK is distributed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0), see [LICENSE](./LICENSE) and [NOTICE](./NOTICE) for more information.