summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--index.go28
-rw-r--r--ws.go6
2 files changed, 21 insertions, 13 deletions
diff --git a/index.go b/index.go
index 35a9840..8db5222 100644
--- a/index.go
+++ b/index.go
@@ -96,19 +96,23 @@ func handleIndex(w http.ResponseWriter, req *http.Request) {
return
}
- err = tmpl.ExecuteTemplate(
- w,
- "index",
- map[string]interface{}{
- "open": true,
- "user": map[string]interface{}{
- "Name": userName,
- "Department": userDepartment,
+ err = func() error {
+ coursesLock.RLock()
+ defer coursesLock.RUnlock()
+ return tmpl.ExecuteTemplate(
+ w,
+ "index",
+ map[string]interface{}{
+ "open": true,
+ "user": map[string]interface{}{
+ "Name": userName,
+ "Department": userDepartment,
+ },
+ "courses": courses,
+ "source": config.Source,
},
- "courses": courses,
- "source": config.Source,
- },
- )
+ )
+ }()
if err != nil {
log.Println(err)
return
diff --git a/ws.go b/ws.go
index 764bbbd..7cc6aab 100644
--- a/ws.go
+++ b/ws.go
@@ -327,7 +327,11 @@ func handleConn(
return protocolError(ctx, c, "Course ID must be an integer")
}
courseID := int(_courseID)
- course := courses[courseID]
+ course := func() *courseT {
+ coursesLock.RLock()
+ defer coursesLock.RUnlock()
+ return courses[courseID]
+ }()
err = func() error {
tx, err := db.Begin(ctx)