support reload (just trying)
This commit is contained in:
parent
19c287b4c8
commit
5edd16b326
2 changed files with 24 additions and 2 deletions
|
@ -35,7 +35,7 @@ func main() {
|
|||
os.Exit(0)
|
||||
}
|
||||
|
||||
mu := megauploader.MegaUploader{Conf: cfg}
|
||||
mu := megauploader.NewMegaUploader(cfg)
|
||||
mu.SetupRoutes()
|
||||
graceful.Run(*addr, 15*time.Second, http.DefaultServeMux)
|
||||
}
|
||||
|
|
24
http.go
24
http.go
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue