allowances/main.go

44 lines
1.3 KiB
Go

package main
import (
"flag"
"fmt"
"github.com/gorilla/sessions"
"html/template"
"log"
"net/http"
)
var addr = flag.String("addr", ":8000", "address I'll listen on.")
var static_files = flag.String("static", "./static", "location of static files")
var passes_file = flag.String("passes", "passwds.json", "the password database")
var db_file = flag.String("children", "children.json", "the children database")
var template_dir = flag.String("templates", "templates", "template dir")
var add_pw = flag.String("passwd", "", "add this pass to the db")
var check_pw = flag.String("checkpw", "", "check if this pw is in db")
var addPath = "/add/"
var store = sessions.NewCookieStore([]byte("hello world"))
var templates *template.Template
func main() {
flag.Parse()
if *add_pw != "" {
add_password(*passes_file, *add_pw)
} else if *check_pw != "" {
fmt.Printf("valid password: %v\n",
check_password(*passes_file, *check_pw))
} else {
http.HandleFunc("/", homeHandler)
http.HandleFunc("/login", loginHandler)
http.HandleFunc("/logout", logoutHandler)
http.HandleFunc(addPath, addHandler)
http.Handle("/s/", http.StripPrefix("/s/",
http.FileServer(http.Dir(*static_files))))
if err := http.ListenAndServe(*addr, nil); err != nil {
log.Fatal("ListenAndServe:", err)
}
}
}