aboutsummaryrefslogtreecommitdiff
path: root/http.go
diff options
context:
space:
mode:
Diffstat (limited to 'http.go')
-rw-r--r--http.go22
1 files changed, 18 insertions, 4 deletions
diff --git a/http.go b/http.go
index fcfd38f..ad42c2b 100644
--- a/http.go
+++ b/http.go
@@ -20,9 +20,12 @@ func (papers *Papers) IndexHandler(w http.ResponseWriter, r *http.Request) {
filepath.Join(templateDir, "index.html"),
filepath.Join(templateDir, "list.html"),
)
+ papers.RLock()
res := Resp{
- Papers: papers.List,
+ Papers: *papers,
}
+ papers.RUnlock()
+
t.Execute(w, &res)
}
@@ -33,9 +36,12 @@ func (papers *Papers) AdminHandler(w http.ResponseWriter, r *http.Request) {
filepath.Join(templateDir, "layout.html"),
filepath.Join(templateDir, "list.html"),
)
+ papers.RLock()
res := Resp{
- Papers: papers.List,
+ Papers: *papers,
}
+ papers.RUnlock()
+
if user != "" && pass != "" {
username, password, ok := r.BasicAuth()
if ok && user == username && pass == password {
@@ -58,9 +64,12 @@ func (papers *Papers) EditHandler(w http.ResponseWriter, r *http.Request) {
filepath.Join(templateDir, "layout.html"),
filepath.Join(templateDir, "list.html"),
)
+ papers.RLock()
res := Resp{
- Papers: papers.List,
+ Papers: *papers,
}
+ papers.RUnlock()
+
if user != "" && pass != "" {
username, password, ok := r.BasicAuth()
if !ok || user != username || pass != password {
@@ -152,7 +161,8 @@ func (papers *Papers) AddHandler(w http.ResponseWriter, r *http.Request) {
// sanitize input; we use the category to build the path used to save
// papers
nc = strings.Trim(strings.Replace(nc, "..", "", -1), "/.")
- res := Resp{Papers: papers.List}
+
+ res := Resp{}
// paper download, both required fields populated
if len(strings.TrimSpace(p)) > 0 && len(strings.TrimSpace(c)) > 0 {
@@ -194,6 +204,10 @@ func (papers *Papers) AddHandler(w http.ResponseWriter, r *http.Request) {
res.Status = fmt.Sprintf("category %q added successfully", nc)
}
}
+ papers.RLock()
+ res.Papers = *papers
+ papers.RUnlock()
+
t.Execute(w, &res)
}