summaryrefslogtreecommitdiff
path: root/index.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--index.go23
1 files changed, 20 insertions, 3 deletions
diff --git a/index.go b/index.go
index 931cd2d..1050207 100644
--- a/index.go
+++ b/index.go
@@ -109,9 +109,26 @@ func handleIndex(w http.ResponseWriter, req *http.Request) {
return
}
+ /*
+ * Copy courses to _courses. The former is a sync.Map and the latter is
+ * a map[int]*courseT, and the former is very difficult to access from
+ * HTML templates.
+ */
+ _courses := make(map[int]*courseT)
+ courses.Range(func(key, value interface{}) bool {
+ courseID, ok := key.(int)
+ if !ok {
+ panic("courses map has non-\"int\" keys")
+ }
+ course, ok := value.(*courseT)
+ if !ok {
+ panic("courses map has non-\"*courseT\" items")
+ }
+ _courses[courseID] = course
+ return true
+ })
+
err = func() error {
- coursesLock.RLock()
- defer coursesLock.RUnlock()
return tmpl.ExecuteTemplate(
w,
"student",
@@ -121,7 +138,7 @@ func handleIndex(w http.ResponseWriter, req *http.Request) {
"Name": userName,
"Department": userDepartment,
},
- "courses": courses,
+ "courses": &_courses,
},
)
}()