-
Notifications
You must be signed in to change notification settings - Fork 8
/
filesystem.go
61 lines (55 loc) · 1.93 KB
/
filesystem.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
package bytengine
import (
"fmt"
"log"
)
var bfsPlugins = make(map[string]FileSystem)
type FileSystem interface {
Start(config string, b *ByteStore) error
ClearAll() ([]string, error)
ListDatabase(filter string) ([]string, error)
CreateDatabase(db string) error
DropDatabase(db string) error
NewDir(p, db string) error
NewFile(p, db string, jsondata map[string]interface{}) error
ListDir(p, filter, db string) (map[string][]string, error)
ReadJson(p, db string, fields []string) (interface{}, error)
Delete(p, db string) error
Rename(p, newname, db string) error
Move(from, to, db string) error
Copy(from, to, db string) error
Info(p, db string) (map[string]interface{}, error)
FileAccess(p, db string, protect bool) error
SetCounter(counter, action string, value int64, db string) (int64, error)
ListCounter(filter, db string) (map[string]int64, error)
WriteBytes(p, ap, db string) (int64, error)
ReadBytes(fp, db string) (string, error)
DirectAccess(fp, db, layer string) (map[string]interface{}, string, error)
DeleteBytes(p, db string) error
UpdateJson(p, db string, j map[string]interface{}) error
BQLSearch(db string, query map[string]interface{}) (interface{}, error)
BQLSet(db string, query map[string]interface{}) (int, error)
BQLUnset(db string, query map[string]interface{}) (int, error)
}
func RegisterFileSystem(name string, plugin FileSystem) {
if plugin == nil {
log.Fatal("File System Plugin Registration: plugin is nil")
}
if _, exists := bfsPlugins[name]; exists {
log.Printf("File System Plugin Registration: plugin %q already registered", name)
return
}
bfsPlugins[name] = plugin
}
func NewFileSystem(pluginName, config string, b *ByteStore) (plugin FileSystem, err error) {
plugin, ok := bfsPlugins[pluginName]
if !ok {
err = fmt.Errorf("File System Plugin Creation: unknown plugin name %q (forgot to import?)", pluginName)
return
}
err = plugin.Start(config, b)
if err != nil {
plugin = nil
}
return
}