allowances/main.go

44 lines
1.3 KiB
Go
Raw Normal View History

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.")
2013-01-06 15:29:31 -08:00
var static_files = flag.String("static", "./static", "location of static files")
2013-02-26 22:30:23 -08:00
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")
2013-02-21 00:19:21 -08:00
var check_pw = flag.String("checkpw", "", "check if this pw is in db")
2013-03-08 22:28:24 -08:00
var addPath = "/add/"
var store = sessions.NewCookieStore([]byte("hello world"))
var templates *template.Template
func main() {
flag.Parse()
if *add_pw != "" {
2013-02-26 22:30:23 -08:00
add_password(*passes_file, *add_pw)
2013-02-21 00:19:21 -08:00
} else if *check_pw != "" {
2013-02-26 22:30:23 -08:00
fmt.Printf("valid password: %v\n",
check_password(*passes_file, *check_pw))
} else {
http.HandleFunc("/", homeHandler)
http.HandleFunc("/login", loginHandler)
2013-02-26 22:39:26 -08:00
http.HandleFunc("/logout", logoutHandler)
2013-03-08 22:28:24 -08:00
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)
}
}
}