-
Notifications
You must be signed in to change notification settings - Fork 0
/
oss.go
41 lines (34 loc) · 808 Bytes
/
oss.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
package huawei
// 引入依赖包
import (
"context"
"io"
"github.com/huaweicloud/huaweicloud-sdk-go-obs/obs"
)
type Oss struct {
client *obs.ObsClient
}
func NewOss(client *obs.ObsClient) *Oss {
return &Oss{client: client}
}
func (h *Oss) Set(ctx context.Context, bucket string, key string, reader io.Reader) (err error) {
input := &obs.PutObjectInput{}
input.Bucket = bucket
input.Key = key
input.Body = reader
_, err = h.client.PutObject(input)
return
}
func (h *Oss) Get(ctx context.Context, bucket string, key string) (resp []byte, err error) {
input := &obs.GetObjectInput{}
input.Bucket = bucket
input.Key = key
output, err := h.client.GetObject(input)
if err != nil {
return
}
defer output.Body.Close()
// 读取对象内容
resp, err = io.ReadAll(output.Body)
return
}