diff options
-rw-r--r-- | index.go | 28 | ||||
-rw-r--r-- | ws.go | 6 |
2 files changed, 21 insertions, 13 deletions
@@ -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 @@ -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) |