-
Notifications
You must be signed in to change notification settings - Fork 30
/
backend.go
56 lines (47 loc) · 969 Bytes
/
backend.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
package backend
import (
"sort"
"sync"
"github.com/c2fo/vfs"
)
var mmu sync.RWMutex
var m map[string]vfs.FileSystem
// Register a new filesystem in backend map
func Register(name string, v vfs.FileSystem) {
mmu.Lock()
m[name] = v
mmu.Unlock()
}
// Unregister unregisters a filesystem from backend map
func Unregister(name string) {
mmu.Lock()
delete(m, name)
mmu.Unlock()
}
// UnregisterAll unregisters all filesystems from backend map
func UnregisterAll() {
// mainly for tests
mmu.Lock()
m = make(map[string]vfs.FileSystem)
mmu.Unlock()
}
// Backend returns the backend filesystem by name
func Backend(name string) vfs.FileSystem {
mmu.RLock()
defer mmu.RUnlock()
return m[name]
}
// RegisteredBackends returns an array of backend names
func RegisteredBackends() []string {
var f []string
mmu.RLock()
for k := range m {
f = append(f, k)
}
mmu.RUnlock()
sort.Strings(f)
return f
}
func init() {
m = make(map[string]vfs.FileSystem)
}