added children db, simple render
This commit is contained in:
parent
9a917e98a5
commit
200f109e19
17
db.go
17
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
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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 }}
|
||||
|
Loading…
Reference in New Issue
Block a user