forked from aliyun/aliyun-oss-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
object_acl.go
executable file
·44 lines (36 loc) · 963 Bytes
/
object_acl.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
package sample
import (
"fmt"
"strings"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
// ObjectACLSample shows how to set and get object ACL
func ObjectACLSample() {
// Create bucket
bucket, err := GetTestBucket(bucketName)
if err != nil {
HandleError(err)
}
// Create object
err = bucket.PutObject(objectKey, strings.NewReader("YoursObjectValue"))
if err != nil {
HandleError(err)
}
// Case 1: Set bucket ACL, valid ACLs are ACLPrivate、ACLPublicRead、ACLPublicReadWrite
err = bucket.SetObjectACL(objectKey, oss.ACLPrivate)
if err != nil {
HandleError(err)
}
// Get object ACL, returns one of the three values: private、public-read、public-read-write
goar, err := bucket.GetObjectACL(objectKey)
if err != nil {
HandleError(err)
}
fmt.Println("Object ACL:", goar.ACL)
// Delete object and bucket
err = DeleteTestBucketAndObject(bucketName)
if err != nil {
HandleError(err)
}
fmt.Println("ObjectACLSample completed")
}