rwlock
License: MIT Signed-off-by: Henrique Dias <hacdias@gmail.com>
This commit is contained in:
parent
1470ec8629
commit
72676f2375
@ -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
|
||||||
|
|||||||
@ -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 ...
|
||||||
|
|||||||
@ -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,
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user