package main import ( "code.google.com/p/go.crypto/bcrypt" "flag" "fmt" "github.com/kuroneko/gosqlite3" "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 db_file = flag.String("db", "./db.sqlite", "the database") var add_pw = flag.String("passwd", "", "add this pass to the db") func main() { flag.Parse() if *add_pw != "" { hpass, err := bcrypt.GenerateFromPassword([]byte(*add_pw), bcrypt.DefaultCost) if err != nil { log.Fatal(err) } db, err := sqlite3.Open(*db_file) defer db.Close() if err != nil { log.Fatal(err) } cmd := fmt.Sprintf("INSERT INTO passes ('id', 'hash') VALUES (null, '%v')", string(hpass)) _, err = db.Execute(cmd) if err != nil { log.Fatal(err) } } else { fmt.Printf("%v\n", *add_pw) http.Handle("/s/", http.StripPrefix("/s/", http.FileServer(http.Dir(*static_files)))) if err := http.ListenAndServe(*addr, nil); err != nil { log.Fatal("ListenAndServe:", err) } } }