-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
getAnonymous.go
46 lines (39 loc) · 858 Bytes
/
getAnonymous.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
package main
import (
"context"
"fmt"
"net/url"
"os"
"strings"
"io/ioutil"
"github.com/mozillazg/go-cos"
)
func upload(c *cos.Client, name string) {
f := strings.NewReader("test")
f = strings.NewReader("test xxx")
opt := &cos.ObjectPutOptions{
ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{
ContentType: "text/html",
},
ACLHeaderOptions: &cos.ACLHeaderOptions{
XCosACL: "public-read",
},
}
c.Object.Put(context.Background(), name, f, opt)
return
}
func main() {
u, _ := url.Parse(os.Getenv("COS_BUCKET_URL"))
b := &cos.BaseURL{BucketURL: u}
c := cos.NewClient(b, nil)
name := "test/anonymous_get.go"
upload(c, name)
resp, err := c.Object.Get(context.Background(), name, nil)
if err != nil {
panic(err)
return
}
bs, _ := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
fmt.Printf("%s\n", string(bs))
}