Skip to content

Commit e0b6838

Browse files
authored
Update the Go Quickstart README (#1896)
* Update the Go Quickstart README to clarify a few steps and make the example easier to follow.
1 parent 4ec0ff8 commit e0b6838

File tree

1 file changed

+91
-27
lines changed

1 file changed

+91
-27
lines changed

README.md

+91-27
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
# 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)
22

3-
The MinIO Go Client SDK provides simple APIs to access any Amazon S3 compatible object storage.
3+
The MinIO Go Client SDK provides straightforward APIs to access any Amazon S3 compatible object storage.
44

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.
6-
For a complete list of APIs and examples, please take a look at the [godoc documentation](https://pkg.go.dev/github.com/minio/minio-go/v7) or [Go Client API Reference](https://min.io/docs/minio/linux/developers/go/API.html).
5+
This Quickstart Guide covers how to install the MinIO client SDK, connect to MinIO, and create a sample file uploader.
6+
For a complete list of APIs and examples, see the [godoc documentation](https://pkg.go.dev/github.com/minio/minio-go/v7) or [Go Client API Reference](https://min.io/docs/minio/linux/developers/go/API.html).
77

8-
This document assumes that you have a working [Go development environment](https://golang.org/doc/install).
8+
These examples presume a working [Go development environment](https://golang.org/doc/install) and the [MinIO `mc` command line tool](https://min.io/docs/minio/linux/reference/minio-mc.html).
99

1010
## Download from Github
11+
12+
From your project directory:
13+
1114
```sh
1215
go get github.com/minio/minio-go/v7
1316
```
1417

15-
## Initialize MinIO Client
16-
MinIO client requires the following four parameters specified to connect to an Amazon S3 compatible object storage.
18+
## Initialize a MinIO Client Object
19+
20+
The MinIO client requires the following parameters to connect to an Amazon S3 compatible object storage:
1721

18-
| Parameter | Description|
19-
| :--- | :--- |
20-
| endpoint | URL to object storage service. |
21-
| _minio.Options_ | All the options such as credentials, custom transport etc. |
22+
| Parameter | Description |
23+
| ----------------- | ---------------------------------------------------------- |
24+
| `endpoint` | URL to object storage service. |
25+
| `_minio.Options_` | All the options such as credentials, custom transport etc. |
2226

2327
```go
2428
package main
@@ -49,13 +53,25 @@ func main() {
4953
}
5054
```
5155

52-
## Quick Start Example - File Uploader
53-
This example program connects to an object storage server, creates a bucket and uploads a file to the bucket.
56+
## Example - File Uploader
5457

55-
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.
58+
This sample code connects to an object storage server, creates a bucket, and uploads a file to the bucket.
59+
It uses the MinIO `play` server, a public MinIO cluster located at [https://play.min.io](https://play.min.io).
60+
61+
The `play` server runs the latest stable version of MinIO and may be used for testing and development.
62+
The access credentials shown in this example are open to the public and all data uploaded to `play` should be considered public and non-protected.
5663

5764
### FileUploader.go
65+
66+
This example does the following:
67+
68+
- Connects to the MinIO `play` server using the provided credentials.
69+
- Creates a bucket named `testbucket`.
70+
- Uploads a file named `testdata` from `/tmp`.
71+
- Verifies the file was created using `mc ls`.
72+
5873
```go
74+
// FileUploader.go MinIO example
5975
package main
6076

6177
import (
@@ -82,8 +98,8 @@ func main() {
8298
log.Fatalln(err)
8399
}
84100

85-
// Make a new bucket called mymusic.
86-
bucketName := "mymusic"
101+
// Make a new bucket called testbucket.
102+
bucketName := "testbucket"
87103
location := "us-east-1"
88104

89105
err = minioClient.MakeBucket(ctx, bucketName, minio.MakeBucketOptions{Region: location})
@@ -99,12 +115,13 @@ func main() {
99115
log.Printf("Successfully created %s\n", bucketName)
100116
}
101117

102-
// Upload the zip file
103-
objectName := "golden-oldies.zip"
104-
filePath := "/tmp/golden-oldies.zip"
105-
contentType := "application/zip"
118+
// Upload the test file
119+
// Change the value of filePath if the file is in another location
120+
objectName := "testdata"
121+
filePath := "/tmp/testdata"
122+
contentType := "application/octet-stream"
106123

107-
// Upload the zip file with FPutObject
124+
// Upload the test file with FPutObject
108125
info, err := minioClient.FPutObject(ctx, bucketName, objectName, filePath, minio.PutObjectOptions{ContentType: contentType})
109126
if err != nil {
110127
log.Fatalln(err)
@@ -114,22 +131,51 @@ func main() {
114131
}
115132
```
116133

117-
### Run FileUploader
134+
**1. Create a test file containing data:**
135+
136+
You can do this with `dd` on Linux or macOS systems:
137+
138+
```sh
139+
dd if=/dev/urandom of=/tmp/testdata bs=2048 count=10
140+
```
141+
142+
or `fsutil` on Windows:
143+
144+
```sh
145+
fsutil file createnew "C:\Users\<username>\Desktop\sample.txt" 20480
146+
```
147+
148+
**2. Run FileUploader with the following commands:**
149+
118150
```sh
119-
go run file-uploader.go
120-
2016/08/13 17:03:28 Successfully created mymusic
121-
2016/08/13 17:03:40 Successfully uploaded golden-oldies.zip of size 16253413
151+
go mod init example/FileUploader
152+
go get github.com/minio/minio-go/v7
153+
go get github.com/minio/minio-go/v7/pkg/credentials
154+
go run FileUploader.go
155+
```
156+
157+
The output resembles the following:
122158

123-
mc ls play/mymusic/
124-
[2016-05-27 16:02:16 PDT] 17MiB golden-oldies.zip
159+
```sh
160+
2023/11/01 14:27:55 Successfully created testbucket
161+
2023/11/01 14:27:55 Successfully uploaded testdata of size 20480
162+
```
163+
164+
**3. Verify the Uploaded File With `mc ls`:**
165+
166+
```sh
167+
mc ls play/testbucket
168+
[2023-11-01 14:27:55 UTC] 20KiB STANDARD TestDataFile
125169
```
126170

127171
## API Reference
172+
128173
The full API Reference is available here.
129174

130175
* [Complete API Reference](https://min.io/docs/minio/linux/developers/go/API.html)
131176

132177
### API Reference : Bucket Operations
178+
133179
* [`MakeBucket`](https://min.io/docs/minio/linux/developers/go/API.html#MakeBucket)
134180
* [`ListBuckets`](https://min.io/docs/minio/linux/developers/go/API.html#ListBuckets)
135181
* [`BucketExists`](https://min.io/docs/minio/linux/developers/go/API.html#BucketExists)
@@ -138,21 +184,25 @@ The full API Reference is available here.
138184
* [`ListIncompleteUploads`](https://min.io/docs/minio/linux/developers/go/API.html#ListIncompleteUploads)
139185

140186
### API Reference : Bucket policy Operations
187+
141188
* [`SetBucketPolicy`](https://min.io/docs/minio/linux/developers/go/API.html#SetBucketPolicy)
142189
* [`GetBucketPolicy`](https://min.io/docs/minio/linux/developers/go/API.html#GetBucketPolicy)
143190

144191
### API Reference : Bucket notification Operations
192+
145193
* [`SetBucketNotification`](https://min.io/docs/minio/linux/developers/go/API.html#SetBucketNotification)
146194
* [`GetBucketNotification`](https://min.io/docs/minio/linux/developers/go/API.html#GetBucketNotification)
147195
* [`RemoveAllBucketNotification`](https://min.io/docs/minio/linux/developers/go/API.html#RemoveAllBucketNotification)
148196
* [`ListenBucketNotification`](https://min.io/docs/minio/linux/developers/go/API.html#ListenBucketNotification) (MinIO Extension)
149197
* [`ListenNotification`](https://min.io/docs/minio/linux/developers/go/API.html#ListenNotification) (MinIO Extension)
150198

151199
### API Reference : File Object Operations
200+
152201
* [`FPutObject`](https://min.io/docs/minio/linux/developers/go/API.html#FPutObject)
153202
* [`FGetObject`](https://min.io/docs/minio/linux/developers/go/API.html#FGetObject)
154203

155204
### API Reference : Object Operations
205+
156206
* [`GetObject`](https://min.io/docs/minio/linux/developers/go/API.html#GetObject)
157207
* [`PutObject`](https://min.io/docs/minio/linux/developers/go/API.html#PutObject)
158208
* [`PutObjectStreaming`](https://min.io/docs/minio/linux/developers/go/API.html#PutObjectStreaming)
@@ -163,21 +213,23 @@ The full API Reference is available here.
163213
* [`RemoveIncompleteUpload`](https://min.io/docs/minio/linux/developers/go/API.html#RemoveIncompleteUpload)
164214
* [`SelectObjectContent`](https://min.io/docs/minio/linux/developers/go/API.html#SelectObjectContent)
165215

166-
167216
### API Reference : Presigned Operations
217+
168218
* [`PresignedGetObject`](https://min.io/docs/minio/linux/developers/go/API.html#PresignedGetObject)
169219
* [`PresignedPutObject`](https://min.io/docs/minio/linux/developers/go/API.html#PresignedPutObject)
170220
* [`PresignedHeadObject`](https://min.io/docs/minio/linux/developers/go/API.html#PresignedHeadObject)
171221
* [`PresignedPostPolicy`](https://min.io/docs/minio/linux/developers/go/API.html#PresignedPostPolicy)
172222

173223
### API Reference : Client custom settings
224+
174225
* [`SetAppInfo`](https://min.io/docs/minio/linux/developers/go/API.html#SetAppInfo)
175226
* [`TraceOn`](https://min.io/docs/minio/linux/developers/go/API.html#TraceOn)
176227
* [`TraceOff`](https://min.io/docs/minio/linux/developers/go/API.html#TraceOff)
177228

178229
## Full Examples
179230

180231
### Full Examples : Bucket Operations
232+
181233
* [makebucket.go](https://github.com/minio/minio-go/blob/master/examples/s3/makebucket.go)
182234
* [listbuckets.go](https://github.com/minio/minio-go/blob/master/examples/s3/listbuckets.go)
183235
* [bucketexists.go](https://github.com/minio/minio-go/blob/master/examples/s3/bucketexists.go)
@@ -187,36 +239,43 @@ The full API Reference is available here.
187239
* [listincompleteuploads.go](https://github.com/minio/minio-go/blob/master/examples/s3/listincompleteuploads.go)
188240

189241
### Full Examples : Bucket policy Operations
242+
190243
* [setbucketpolicy.go](https://github.com/minio/minio-go/blob/master/examples/s3/setbucketpolicy.go)
191244
* [getbucketpolicy.go](https://github.com/minio/minio-go/blob/master/examples/s3/getbucketpolicy.go)
192245
* [listbucketpolicies.go](https://github.com/minio/minio-go/blob/master/examples/s3/listbucketpolicies.go)
193246

194247
### Full Examples : Bucket lifecycle Operations
248+
195249
* [setbucketlifecycle.go](https://github.com/minio/minio-go/blob/master/examples/s3/setbucketlifecycle.go)
196250
* [getbucketlifecycle.go](https://github.com/minio/minio-go/blob/master/examples/s3/getbucketlifecycle.go)
197251

198252
### Full Examples : Bucket encryption Operations
253+
199254
* [setbucketencryption.go](https://github.com/minio/minio-go/blob/master/examples/s3/setbucketencryption.go)
200255
* [getbucketencryption.go](https://github.com/minio/minio-go/blob/master/examples/s3/getbucketencryption.go)
201256
* [deletebucketencryption.go](https://github.com/minio/minio-go/blob/master/examples/s3/deletebucketencryption.go)
202257

203258
### Full Examples : Bucket replication Operations
259+
204260
* [setbucketreplication.go](https://github.com/minio/minio-go/blob/master/examples/s3/setbucketreplication.go)
205261
* [getbucketreplication.go](https://github.com/minio/minio-go/blob/master/examples/s3/getbucketreplication.go)
206262
* [removebucketreplication.go](https://github.com/minio/minio-go/blob/master/examples/s3/removebucketreplication.go)
207263

208264
### Full Examples : Bucket notification Operations
265+
209266
* [setbucketnotification.go](https://github.com/minio/minio-go/blob/master/examples/s3/setbucketnotification.go)
210267
* [getbucketnotification.go](https://github.com/minio/minio-go/blob/master/examples/s3/getbucketnotification.go)
211268
* [removeallbucketnotification.go](https://github.com/minio/minio-go/blob/master/examples/s3/removeallbucketnotification.go)
212269
* [listenbucketnotification.go](https://github.com/minio/minio-go/blob/master/examples/minio/listenbucketnotification.go) (MinIO Extension)
213270
* [listennotification.go](https://github.com/minio/minio-go/blob/master/examples/minio/listen-notification.go) (MinIO Extension)
214271

215272
### Full Examples : File Object Operations
273+
216274
* [fputobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/fputobject.go)
217275
* [fgetobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/fgetobject.go)
218276

219277
### Full Examples : Object Operations
278+
220279
* [putobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/putobject.go)
221280
* [getobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/getobject.go)
222281
* [statobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/statobject.go)
@@ -226,23 +285,28 @@ The full API Reference is available here.
226285
* [removeobjects.go](https://github.com/minio/minio-go/blob/master/examples/s3/removeobjects.go)
227286

228287
### Full Examples : Encrypted Object Operations
288+
229289
* [put-encrypted-object.go](https://github.com/minio/minio-go/blob/master/examples/s3/put-encrypted-object.go)
230290
* [get-encrypted-object.go](https://github.com/minio/minio-go/blob/master/examples/s3/get-encrypted-object.go)
231291
* [fput-encrypted-object.go](https://github.com/minio/minio-go/blob/master/examples/s3/fputencrypted-object.go)
232292

233293
### Full Examples : Presigned Operations
294+
234295
* [presignedgetobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/presignedgetobject.go)
235296
* [presignedputobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/presignedputobject.go)
236297
* [presignedheadobject.go](https://github.com/minio/minio-go/blob/master/examples/s3/presignedheadobject.go)
237298
* [presignedpostpolicy.go](https://github.com/minio/minio-go/blob/master/examples/s3/presignedpostpolicy.go)
238299

239300
## Explore Further
301+
240302
* [Godoc Documentation](https://pkg.go.dev/github.com/minio/minio-go/v7)
241303
* [Complete Documentation](https://min.io/docs/minio/kubernetes/upstream/index.html)
242304
* [MinIO Go Client SDK API Reference](https://min.io/docs/minio/linux/developers/go/API.html)
243305

244306
## Contribute
307+
245308
[Contributors Guide](https://github.com/minio/minio-go/blob/master/CONTRIBUTING.md)
246309

247310
## License
311+
248312
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.

0 commit comments

Comments
 (0)