|
@@ -12,6 +12,7 @@ import (
|
|
|
"path"
|
|
|
"path/filepath"
|
|
|
"strings"
|
|
|
+ "sync"
|
|
|
|
|
|
rice "github.com/GeertJohan/go.rice"
|
|
|
"github.com/c2h5oh/datasize"
|
|
@@ -20,7 +21,28 @@ import (
|
|
|
// MegaUploader acts as controller for all the application. Since this is inherently a web-focused
|
|
|
// application, it will include http utils
|
|
|
type MegaUploader struct {
|
|
|
- Conf Config
|
|
|
+ Conf Config
|
|
|
+ configLock *sync.RWMutex
|
|
|
+}
|
|
|
+
|
|
|
+// NewMegaUploader create a new mega uploader
|
|
|
+func NewMegaUploader(c Config) MegaUploader {
|
|
|
+ return MegaUploader{Conf: c, configLock: new(sync.RWMutex)}
|
|
|
+}
|
|
|
+
|
|
|
+func (mu *MegaUploader) ChangeConf(newconf Config) {
|
|
|
+ mu.configLock.Lock()
|
|
|
+ mu.Conf = newconf
|
|
|
+ mu.configLock.Unlock()
|
|
|
+}
|
|
|
+
|
|
|
+// confAcquire is a middleware to read-lock configuration
|
|
|
+func (mu *MegaUploader) confAcquire(inner func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request) {
|
|
|
+ return func(w http.ResponseWriter, r *http.Request) {
|
|
|
+ mu.configLock.RLock()
|
|
|
+ inner(w, r)
|
|
|
+ mu.configLock.RUnlock()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// SetupRoutes adds API routes
|