-
Notifications
You must be signed in to change notification settings - Fork 231
/
new_bucket.go
50 lines (41 loc) · 912 Bytes
/
new_bucket.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package sample
import (
"fmt"
"strings"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
// NewBucketSample shows how to initialize client and bucket
func NewBucketSample() {
// New client
client, err := oss.New(endpoint, accessID, accessKey)
if err != nil {
HandleError(err)
}
// Create bucket
err = client.CreateBucket(bucketName)
if err != nil {
HandleError(err)
}
// New bucket
bucket, err := client.Bucket(bucketName)
if err != nil {
HandleError(err)
}
// Put object, uploads an object
var objectName = "myobject"
err = bucket.PutObject(objectName, strings.NewReader("MyObjectValue"))
if err != nil {
HandleError(err)
}
// Delete object, deletes an object
err = bucket.DeleteObject(objectName)
if err != nil {
HandleError(err)
}
// Delete bucket
err = client.DeleteBucket(bucketName)
if err != nil {
HandleError(err)
}
fmt.Println("NewBucketSample completed")
}