added children db, simple render

This commit is contained in:
Stephen McQuay 2013-03-04 21:56:39 -08:00
parent 9a917e98a5
commit 200f109e19
3 changed files with 28 additions and 2 deletions

17
db.go
View File

@ -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
}

View File

@ -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) {

View File

@ -2,6 +2,13 @@
{{ define "content" }}
<div class="container pw">
This will have stuff
This will have stuff {{ .children }}
<ul>
{{ range .children }}
<li>
{{ .Name }} {{ .Money }}
</li>
{{ end }}
</ul>
</div>
{{ end }}