-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbytestore.go
52 lines (45 loc) · 1.11 KB
/
bytestore.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
package bytengine
import (
"fmt"
"io"
"log"
"os"
)
var (
// to be expanded
MimeList = map[string]string{
".js": "text/javascript",
".css": "text/css",
}
bstPlugins = make(map[string]ByteStore)
)
type ByteStore interface {
Start(config string) error
Add(db string, file *os.File) (map[string]interface{}, error)
Update(db, id string, file *os.File) (map[string]interface{}, error)
Delete(db, id string) error
Read(db, filename string, file io.Writer) error
DropDatabase(db string) error
}
func RegisterByteStore(name string, plugin ByteStore) {
if plugin == nil {
log.Fatal("Byte Store Plugin Registration: plugin is nil")
}
if _, exists := bstPlugins[name]; exists {
log.Printf("Byte Store Plugin Registration: plugin %q already registered", name)
return
}
bstPlugins[name] = plugin
}
func NewByteStore(pluginName, config string) (plugin ByteStore, err error) {
plugin, ok := bstPlugins[pluginName]
if !ok {
err = fmt.Errorf("Byte Store Plugin Creation: unknown plugin name %q (forgot to import?)", pluginName)
return
}
err = plugin.Start(config)
if err != nil {
plugin = nil
}
return
}