-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsample.go
68 lines (57 loc) · 1.54 KB
/
sample.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"github.com/NetEase-Object-Storage/nos-golang-sdk/config"
"github.com/NetEase-Object-Storage/nos-golang-sdk/logger"
"github.com/NetEase-Object-Storage/nos-golang-sdk/model"
"github.com/NetEase-Object-Storage/nos-golang-sdk/nosclient"
)
func sample_init(endpoint, accessKey, secretKey string) *nosclient.NosClient {
conf := &config.Config{
Endpoint: endpoint,
AccessKey: accessKey,
SecretKey: secretKey,
NosServiceConnectTimeout: 3,
NosServiceReadWriteTimeout: 60,
NosServiceMaxIdleConnection: 100,
LogLevel: logger.LogLevel(logger.DEBUG),
Logger: logger.NewDefaultLogger(),
}
nosClient, _ := nosclient.New(conf)
return nosClient
}
func main() {
path := "<File Path>"
endpoint := "<endpoint>"
accessKey := "<AccessKeyId>"
secretKey := "<SecretKey>"
nosClient := sample_init(endpoint, accessKey, secretKey)
putObjectRequest := &model.PutObjectRequest{
Bucket: "<my-bucket>",
Object: "<my-object>",
FilePath: path,
}
_, err := nosClient.PutObjectByFile(putObjectRequest)
if err != nil {
fmt.Println(err.Error())
}
getObjectRequest := &model.GetObjectRequest{
Bucket: "<my-bucket>",
Object: "<my-object>",
}
objectResult, err := nosClient.GetObject(getObjectRequest)
if err != nil {
fmt.Println(err.Error())
} else {
objectResult.Body.Close()
}
objectRequest := &model.ObjectRequest{
Bucket: "<my-bucket>",
Object: "<my-object>",
}
err = nosClient.DeleteObject(objectRequest)
if err != nil {
fmt.Println(err.Error())
}
fmt.Println("Simple samples completed")
}