README.md (12601B)
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](https://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://min.io/docs/minio/linux/developers/go/API.html). 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 go get github.com/minio/minio-go/v7 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 | _minio.Options_ | All the options such as credentials, custom transport etc. | 21 22 ```go 23 package main 24 25 import ( 26 "log" 27 28 "github.com/minio/minio-go/v7" 29 "github.com/minio/minio-go/v7/pkg/credentials" 30 ) 31 32 func main() { 33 endpoint := "play.min.io" 34 accessKeyID := "Q3AM3UQ867SPQQA43P2F" 35 secretAccessKey := "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG" 36 useSSL := true 37 38 // Initialize minio client object. 39 minioClient, err := minio.New(endpoint, &minio.Options{ 40 Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""), 41 Secure: useSSL, 42 }) 43 if err != nil { 44 log.Fatalln(err) 45 } 46 47 log.Printf("%#v\n", minioClient) // minioClient is now set up 48 } 49 ``` 50 51 ## Quick Start Example - File Uploader 52 This example program connects to an object storage server, creates a bucket and uploads a file to the bucket. 53 54 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. 55 56 ### FileUploader.go 57 ```go 58 package main 59 60 import ( 61 "context" 62 "log" 63 64 "github.com/minio/minio-go/v7" 65 "github.com/minio/minio-go/v7/pkg/credentials" 66 ) 67 68 func main() { 69 ctx := context.Background() 70 endpoint := "play.min.io" 71 accessKeyID := "Q3AM3UQ867SPQQA43P2F" 72 secretAccessKey := "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG" 73 useSSL := true 74 75 // Initialize minio client object. 76 minioClient, err := minio.New(endpoint, &minio.Options{ 77 Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""), 78 Secure: useSSL, 79 }) 80 if err != nil { 81 log.Fatalln(err) 82 } 83 84 // Make a new bucket called mymusic. 85 bucketName := "mymusic" 86 location := "us-east-1" 87 88 err = minioClient.MakeBucket(ctx, bucketName, minio.MakeBucketOptions{Region: location}) 89 if err != nil { 90 // Check to see if we already own this bucket (which happens if you run this twice) 91 exists, errBucketExists := minioClient.BucketExists(ctx, bucketName) 92 if errBucketExists == nil && exists { 93 log.Printf("We already own %s\n", bucketName) 94 } else { 95 log.Fatalln(err) 96 } 97 } else { 98 log.Printf("Successfully created %s\n", bucketName) 99 } 100 101 // Upload the zip file 102 objectName := "golden-oldies.zip" 103 filePath := "/tmp/golden-oldies.zip" 104 contentType := "application/zip" 105 106 // Upload the zip file with FPutObject 107 info, err := minioClient.FPutObject(ctx, bucketName, objectName, filePath, minio.PutObjectOptions{ContentType: contentType}) 108 if err != nil { 109 log.Fatalln(err) 110 } 111 112 log.Printf("Successfully uploaded %s of size %d\n", objectName, info.Size) 113 } 114 ``` 115 116 ### Run FileUploader 117 ```sh 118 go run file-uploader.go 119 2016/08/13 17:03:28 Successfully created mymusic 120 2016/08/13 17:03:40 Successfully uploaded golden-oldies.zip of size 16253413 121 122 mc ls play/mymusic/ 123 [2016-05-27 16:02:16 PDT] 17MiB golden-oldies.zip 124 ``` 125 126 ## API Reference 127 The full API Reference is available here. 128 129 * [Complete API Reference](https://min.io/docs/minio/linux/developers/go/API.html) 130 131 ### API Reference : Bucket Operations 132 * [`MakeBucket`](https://min.io/docs/minio/linux/developers/go/API.html#MakeBucket) 133 * [`ListBuckets`](https://min.io/docs/minio/linux/developers/go/API.html#ListBuckets) 134 * [`BucketExists`](https://min.io/docs/minio/linux/developers/go/API.html#BucketExists) 135 * [`RemoveBucket`](https://min.io/docs/minio/linux/developers/go/API.html#RemoveBucket) 136 * [`ListObjects`](https://min.io/docs/minio/linux/developers/go/API.html#ListObjects) 137 * [`ListIncompleteUploads`](https://min.io/docs/minio/linux/developers/go/API.html#ListIncompleteUploads) 138 139 ### API Reference : Bucket policy Operations 140 * [`SetBucketPolicy`](https://min.io/docs/minio/linux/developers/go/API.html#SetBucketPolicy) 141 * [`GetBucketPolicy`](https://min.io/docs/minio/linux/developers/go/API.html#GetBucketPolicy) 142 143 ### API Reference : Bucket notification Operations 144 * [`SetBucketNotification`](https://min.io/docs/minio/linux/developers/go/API.html#SetBucketNotification) 145 * [`GetBucketNotification`](https://min.io/docs/minio/linux/developers/go/API.html#GetBucketNotification) 146 * [`RemoveAllBucketNotification`](https://min.io/docs/minio/linux/developers/go/API.html#RemoveAllBucketNotification) 147 * [`ListenBucketNotification`](https://min.io/docs/minio/linux/developers/go/API.html#ListenBucketNotification) (MinIO Extension) 148 * [`ListenNotification`](https://min.io/docs/minio/linux/developers/go/API.html#ListenNotification) (MinIO Extension) 149 150 ### API Reference : File Object Operations 151 * [`FPutObject`](https://min.io/docs/minio/linux/developers/go/API.html#FPutObject) 152 * [`FGetObject`](https://min.io/docs/minio/linux/developers/go/API.html#FGetObject) 153 154 ### API Reference : Object Operations 155 * [`GetObject`](https://min.io/docs/minio/linux/developers/go/API.html#GetObject) 156 * [`PutObject`](https://min.io/docs/minio/linux/developers/go/API.html#PutObject) 157 * [`PutObjectStreaming`](https://min.io/docs/minio/linux/developers/go/API.html#PutObjectStreaming) 158 * [`StatObject`](https://min.io/docs/minio/linux/developers/go/API.html#StatObject) 159 * [`CopyObject`](https://min.io/docs/minio/linux/developers/go/API.html#CopyObject) 160 * [`RemoveObject`](https://min.io/docs/minio/linux/developers/go/API.html#RemoveObject) 161 * [`RemoveObjects`](https://min.io/docs/minio/linux/developers/go/API.html#RemoveObjects) 162 * [`RemoveIncompleteUpload`](https://min.io/docs/minio/linux/developers/go/API.html#RemoveIncompleteUpload) 163 * [`SelectObjectContent`](https://min.io/docs/minio/linux/developers/go/API.html#SelectObjectContent) 164 165 166 ### API Reference : Presigned Operations 167 * [`PresignedGetObject`](https://min.io/docs/minio/linux/developers/go/API.html#PresignedGetObject) 168 * [`PresignedPutObject`](https://min.io/docs/minio/linux/developers/go/API.html#PresignedPutObject) 169 * [`PresignedHeadObject`](https://min.io/docs/minio/linux/developers/go/API.html#PresignedHeadObject) 170 * [`PresignedPostPolicy`](https://min.io/docs/minio/linux/developers/go/API.html#PresignedPostPolicy) 171 172 ### API Reference : Client custom settings 173 * [`SetAppInfo`](https://min.io/docs/minio/linux/developers/go/API.html#SetAppInfo) 174 * [`TraceOn`](https://min.io/docs/minio/linux/developers/go/API.html#TraceOn) 175 * [`TraceOff`](https://min.io/docs/minio/linux/developers/go/API.html#TraceOff) 176 177 ## Full Examples 178 179 ### Full Examples : Bucket Operations 180 * [makebucket.go](https://github.com/minio/minio-go/blob/master/examples/s3/makebucket.go) 181 * [listbuckets.go](https://github.com/minio/minio-go/blob/master/examples/s3/listbuckets.go) 182 * [bucketexists.go](https://github.com/minio/minio-go/blob/master/examples/s3/bucketexists.go) 183 * [removebucket.go](https://github.com/minio/minio-go/blob/master/examples/s3/removebucket.go) 184 * [listobjects.go](https://github.com/minio/minio-go/blob/master/examples/s3/listobjects.go) 185 * [listobjectsV2.go](https://github.com/minio/minio-go/blob/master/examples/s3/listobjectsV2.go) 186 * [listincompleteuploads.go](https://github.com/minio/minio-go/blob/master/examples/s3/listincompleteuploads.go) 187 188 ### Full Examples : Bucket policy Operations 189 * [setbucketpolicy.go](https://github.com/minio/minio-go/blob/master/examples/s3/setbucketpolicy.go) 190 * [getbucketpolicy.go](https://github.com/minio/minio-go/blob/master/examples/s3/getbucketpolicy.go) 191 * [listbucketpolicies.go](https://github.com/minio/minio-go/blob/master/examples/s3/listbucketpolicies.go) 192 193 ### Full Examples : Bucket lifecycle Operations 194 * [setbucketlifecycle.go](https://github.com/minio/minio-go/blob/master/examples/s3/setbucketlifecycle.go) 195 * [getbucketlifecycle.go](https://github.com/minio/minio-go/blob/master/examples/s3/getbucketlifecycle.go) 196 197 ### Full Examples : Bucket encryption Operations 198 * [setbucketencryption.go](https://github.com/minio/minio-go/blob/master/examples/s3/setbucketencryption.go) 199 * [getbucketencryption.go](https://github.com/minio/minio-go/blob/master/examples/s3/getbucketencryption.go) 200 * [deletebucketencryption.go](https://github.com/minio/minio-go/blob/master/examples/s3/deletebucketencryption.go) 201 202 ### Full Examples : Bucket replication Operations 203 * [setbucketreplication.go](https://github.com/minio/minio-go/blob/master/examples/s3/setbucketreplication.go) 204 * [getbucketreplication.go](https://github.com/minio/minio-go/blob/master/examples/s3/getbucketreplication.go) 205 * [removebucketreplication.go](https://github.com/minio/minio-go/blob/master/examples/s3/removebucketreplication.go) 206 207 ### Full Examples : Bucket notification Operations 208 * [setbucketnotification.go](https://github.com/minio/minio-go/blob/master/examples/s3/setbucketnotification.go) 209 * [getbucketnotification.go](https://github.com/minio/minio-go/blob/master/examples/s3/getbucketnotification.go) 210 * [removeallbucketnotification.go](https://github.com/minio/minio-go/blob/master/examples/s3/removeallbucketnotification.go) 211 * [listenbucketnotification.go](https://github.com/minio/minio-go/blob/master/examples/minio/listenbucketnotification.go) (MinIO Extension) 212 * [listennotification.go](https://github.com/minio/minio-go/blob/master/examples/minio/listen-notification.go) (MinIO Extension) 213 214 ### Full Examples : File Object Operations 215 * [fputobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/fputobject.go) 216 * [fgetobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/fgetobject.go) 217 218 ### Full Examples : Object Operations 219 * [putobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/putobject.go) 220 * [getobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/getobject.go) 221 * [statobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/statobject.go) 222 * [copyobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/copyobject.go) 223 * [removeobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/removeobject.go) 224 * [removeincompleteupload.go](https://github.com/minio/minio-go/blob/master/examples/s3/removeincompleteupload.go) 225 * [removeobjects.go](https://github.com/minio/minio-go/blob/master/examples/s3/removeobjects.go) 226 227 ### Full Examples : Encrypted Object Operations 228 * [put-encrypted-object.go](https://github.com/minio/minio-go/blob/master/examples/s3/put-encrypted-object.go) 229 * [get-encrypted-object.go](https://github.com/minio/minio-go/blob/master/examples/s3/get-encrypted-object.go) 230 * [fput-encrypted-object.go](https://github.com/minio/minio-go/blob/master/examples/s3/fputencrypted-object.go) 231 232 ### Full Examples : Presigned Operations 233 * [presignedgetobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/presignedgetobject.go) 234 * [presignedputobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/presignedputobject.go) 235 * [presignedheadobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/presignedheadobject.go) 236 * [presignedpostpolicy.go](https://github.com/minio/minio-go/blob/master/examples/s3/presignedpostpolicy.go) 237 238 ## Explore Further 239 * [Complete Documentation](https://min.io/docs/minio/kubernetes/upstream/index.html) 240 * [MinIO Go Client SDK API Reference](https://min.io/docs/minio/linux/developers/go/API.html) 241 242 ## Contribute 243 [Contributors Guide](https://github.com/minio/minio-go/blob/master/CONTRIBUTING.md) 244 245 ## License 246 This SDK is distributed under the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0), see [LICENSE](https://github.com/minio/minio-go/blob/master/LICENSE) and [NOTICE](https://github.com/minio/minio-go/blob/master/NOTICE) for more information.