39 lines
1.1 KiB
Go
39 lines
1.1 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 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 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.Handle("/s/", http.StripPrefix("/s/",
|
|
http.FileServer(http.Dir(*static_files))))
|
|
if err := http.ListenAndServe(*addr, nil); err != nil {
|
|
log.Fatal("ListenAndServe:", err)
|
|
}
|
|
}
|
|
}
|