-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
81 lines (79 loc) · 2.14 KB
/
main.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
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"fmt"
"github.com/pkg6/go-flysystem"
"github.com/pkg6/go-flysystem/config"
"github.com/pkg6/go-flysystem/fsbos"
"github.com/pkg6/go-flysystem/fscloudstorage"
"github.com/pkg6/go-flysystem/fscos"
"github.com/pkg6/go-flysystem/fskodo"
"github.com/pkg6/go-flysystem/fsoss"
"github.com/pkg6/go-flysystem/local"
"github.com/pkg6/gfs/bosfs"
"google.golang.org/api/option"
"strings"
)
func main() {
c := config.Config{
LOCAL: &local.Config{Root: "./_example/test_data"},
OSS: &fsoss.Config{},
BOS: &fsbos.Config{
Endpoint: bosfs.DefaultEndpoint,
Ak: "Ak",
Sk: "Sk",
Bucket: "test bucket",
},
COS: &fscos.Config{
BucketURL: "https://bucket-id.cos.ap-beijing.myqcloud.com",
SecretID: "SecretID",
SecretKey: "SecretKey",
},
KODO: &fskodo.Config{
AccessKey: "AccessKey",
SecretKey: "SecretKey",
Bucket: "test bucket",
},
CloudStorage: &fscloudstorage.Config{
Bucket: "test bucket",
Option: []option.ClientOption{
option.WithCredentialsFile("CredentialsFile.json"),
},
},
}
//Define the root directory of the local adapter
root := "./_example/test_data"
//Initialize the adapter
adapters, err := flysystem.NewConfig(&c)
fmt.Println(err)
_, err = adapters.WriteReader("4.txt", strings.NewReader("test"))
fmt.Println(err)
//Write file
_, err = adapters.Write("1.txt", []byte("test data"))
fmt.Println(err)
//Write data from resource file
_, err = adapters.WriteStream("2.txt", root+"/1.txt")
fmt.Println(err)
//Update file
_, err = adapters.Update("1.txt", []byte("test update data"))
fmt.Println(err)
//Update data from resource file
_, err = adapters.UpdateStream("2.txt", root+"/1.txt")
fmt.Println(err)
exists, _ := adapters.Exists("2.txt")
fmt.Println(exists)
//Read file
read, err := adapters.Read("2.txt")
fmt.Println(read, err)
//Get file mime type
mimeType, err := adapters.MimeType("2.txt")
fmt.Println(mimeType, err)
//Get file size
size, err := adapters.Size("2.txt")
fmt.Println(size, err)
//Move file
_, err = adapters.Move("1.txt", "4.txt")
fmt.Println(err)
//Copy file
_, err = adapters.Copy("2.txt", "5.txt")
fmt.Println(err)
}