示例#1
0
文件: main.go 项目: oesmith/agr
func main() {
	flag.Parse()
	d, err := db.Open(*dbPath)
	if err != nil {
		log.Fatal("Unable to open database:", err.Error())
	}
	a := auth.New(d)
	r := mux.NewRouter()
	r.HandleFunc("/api/v1/auth/login", a.LoginHandler)
	r.HandleFunc("/api/v1/auth/logout", a.LogoutHandler)
	r.Handle("/api/v1/auth/ping", a.PingHandler)
	http.Handle("/", r)
	log.Print("Listening on :8080...")
	log.Fatal(http.ListenAndServe(":8080", nil))
}
示例#2
0
文件: main.go 项目: oesmith/agr
func main() {
	var err error
	flag.Parse()
	if *command == "" {
		log.Fatal("ERROR: -c required")
	}
	if *databasePath == "" {
		log.Fatal("ERROR: -db required")
	}
	d, err = db.Open(*databasePath)
	if err != nil {
		log.Fatal("ERROR:", err)
	}
	a = auth.New(d)
	fn, ok := commands[*command]
	if !ok {
		log.Fatal("ERROR: Invalid command:", *command)
	}
	fn()
}