License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
This commit is contained in:
Henrique Dias 2019-01-02 20:07:05 +00:00
parent 1470ec8629
commit 72676f2375
5 changed files with 16 additions and 1 deletions

View File

@ -29,6 +29,9 @@ type signupBody struct {
} }
func (e *Env) signupHandler(w http.ResponseWriter, r *http.Request) { func (e *Env) signupHandler(w http.ResponseWriter, r *http.Request) {
e.mux.RLock()
defer e.mux.RUnlock()
if !e.Settings.Signup { if !e.Settings.Signup {
httpErr(w, r, http.StatusForbidden, nil) httpErr(w, r, http.StatusForbidden, nil)
return return

View File

@ -29,7 +29,7 @@ type Env struct {
Auther types.Auther Auther types.Auther
Settings *types.Settings Settings *types.Settings
Store *types.Store Store *types.Store
mux sync.Mutex // settings mutex for Auther, Runner and Settings changes. mux sync.RWMutex // settings mutex for Settings changes.
} }
// Handler ... // Handler ...

View File

@ -23,6 +23,9 @@ func (e *Env) settingsGetHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
e.mux.RLock()
defer e.mux.RUnlock()
data := &settingsData{ data := &settingsData{
Signup: e.Settings.Signup, Signup: e.Settings.Signup,
Defaults: e.Settings.Defaults, Defaults: e.Settings.Defaults,

View File

@ -15,6 +15,9 @@ import (
) )
func (e *Env) getStaticData() map[string]interface{} { func (e *Env) getStaticData() map[string]interface{} {
e.mux.RLock()
defer e.mux.RUnlock()
staticURL := strings.TrimPrefix(e.Settings.BaseURL+"/static", "/") staticURL := strings.TrimPrefix(e.Settings.BaseURL+"/static", "/")
data := map[string]interface{}{ data := map[string]interface{}{
@ -85,6 +88,9 @@ func (e *Env) getStaticHandlers() (http.Handler, http.Handler) {
}) })
static := http.StripPrefix("/static/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { static := http.StripPrefix("/static/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
e.mux.RLock()
defer e.mux.RUnlock()
if e.Settings.Branding.Files != "" { if e.Settings.Branding.Files != "" {
if strings.HasPrefix(r.URL.Path, "img/") { if strings.HasPrefix(r.URL.Path, "img/") {
path := filepath.Join(e.Settings.Branding.Files, r.URL.Path) path := filepath.Join(e.Settings.Branding.Files, r.URL.Path)

View File

@ -61,7 +61,10 @@ func (e *Env) commandsHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
e.mux.RLock()
command, err := e.Settings.ParseCommand(raw) command, err := e.Settings.ParseCommand(raw)
e.mux.RUnlock()
if err != nil { if err != nil {
err := conn.WriteMessage(websocket.TextMessage, []byte(err.Error())) err := conn.WriteMessage(websocket.TextMessage, []byte(err.Error()))
if err != nil { if err != nil {