/
doc.go
75 lines (57 loc) · 1.67 KB
/
doc.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
/*
Package backend provides a means of allowing backend filesystems to self-register on load via an init() call to
backend.Register("some name", vfs.Filesystem)
In this way, a caller of vfs backends can simply load the backend filesystem (and ONLY those needed) and begin using it:
package main
// import backend and each backend you intend to use
import(
"github.com/c2fo/vfs/backend"
"github.com/c2fo/vfs/backend/os"
"github.com/c2fo/vfs/backend/s3"
)
func main() {
var err error
var osfile, s3file vfs.File
// THEN begin using the filesystems
osfile, err = backend.Backend(os.Scheme).NewFile("", "/path/to/file.txt")
if err != nil {
panic(err)
}
s3file, err = backend.Backend(s3.Scheme).NewFile("mybucket", "/some/file.txt")
if err != nil {
panic(err)
}
err = osfile.CopyTo(s3file)
if err != nil {
panic(err)
}
}
Development
To create your own backend, you must create a package that implements the interfaces: vfs.Filesystem, vfs.Location, and vfs.File.
Then ensure it registers itself on load:
package myexoticfilesystem
import(
...
"github.com/c2fo/vfs"
"github.com/c2fo/vfs/backend"
)
// IMPLEMENT vfs interfaces
...
// register backend
func init() {
backend.Register("exfs", &MyExoticFilesystem{})
}
Then do use it in some other package do
package MyExoticFilesystem
import(
"github.com/c2fo/vfs/backend"
"github.com/acme/myexoticfilesystem"
)
...
func useNewBackend() error {
myExoticFs, err = backend.Backend(myexoticfilesystem.Scheme)
...
}
That's it. Simple.
*/
package backend