diff --git a/db.go b/db.go index b9d4545..503530b 100644 --- a/db.go +++ b/db.go @@ -5,8 +5,11 @@ import ( "encoding/json" "io/ioutil" "log" + "sync" ) +var dbMutex = sync.RWMutex{} + func get_passes(filename string) (cur_passes []string, err error) { b, err := ioutil.ReadFile(filename) if err != nil { @@ -49,3 +52,17 @@ func check_password(filename, attempt string) (result bool) { } return } + +func loadChildren(filename string) (children []Child) { + dbMutex.RLock() + defer dbMutex.RUnlock() + b, err := ioutil.ReadFile(filename) + if err != nil { + log.Fatal(err) + } + err = json.Unmarshal(b, &children) + if err != nil { + log.Fatal(err) + } + return +} diff --git a/handlers.go b/handlers.go index cb8a59f..fd57fc2 100644 --- a/handlers.go +++ b/handlers.go @@ -10,7 +10,9 @@ func homeHandler(w http.ResponseWriter, req *http.Request) { if loggedIn == nil { http.Redirect(w, req, "/login", http.StatusSeeOther) } - T("index.html").Execute(w, map[string]interface{}{}) + children := loadChildren(*db_file) + T("index.html").Execute(w, map[string]interface{}{ + "children": children,}) } func loginHandler(w http.ResponseWriter, req *http.Request) { diff --git a/templates/index.html b/templates/index.html index 95b24dc..7e9a3f6 100644 --- a/templates/index.html +++ b/templates/index.html @@ -2,6 +2,13 @@ {{ define "content" }}
- This will have stuff + This will have stuff {{ .children }} +
{{ end }}