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
package httpd
import (
"sync"
"github.com/LeeEirc/elfinder"
)
type VolumeCloser interface {
elfinder.Volume
Close()
}
var userVolumes = make(map[string]VolumeCloser)
var volumeLock = new(sync.RWMutex)
func addUserVolume(sid string, v VolumeCloser) {
volumeLock.Lock()
defer volumeLock.Unlock()
userVolumes[sid] = v
}
func removeUserVolume(sid string) {
volumeLock.RLock()
v, ok := userVolumes[sid]
volumeLock.RUnlock()
if !ok {
return
}
v.Close()
volumeLock.Lock()
delete(userVolumes, sid)
volumeLock.Unlock()
}
func GetUserVolume(sid string) (VolumeCloser, bool) {
volumeLock.RLock()
defer volumeLock.RUnlock()
v, ok := userVolumes[sid]
return v, ok
}