Exemplo n.º 1
0
func main() {
	cpu := runtime.NumCPU()
	runtime.GOMAXPROCS(cpu)

	db_root := os.Args[1]
	web_root := os.Args[2]

	var web_port string
	if len(os.Args) == 4 {
		web_port = os.Args[3]
	} else {
		web_port = "8080"
	}

	db := model.NewDatabase(db_root)
	update_disk := true
	minify := true
	force_reload := true
	db.Load(update_disk, minify, force_reload)
	println("Serving...")

	http.HandleFunc("/q",
		func(w http.ResponseWriter, r *http.Request) {
			model.HandleQuery(w, r, db)
		})
	http.HandleFunc("/montage/",
		func(w http.ResponseWriter, r *http.Request) {
			model.HandleMontage(w, r, db)
		})
	http.HandleFunc("/set",
		func(w http.ResponseWriter, r *http.Request) {
			model.HandleSet(w, r, db)
		})
	http.HandleFunc("/viewer",
		func(w http.ResponseWriter, r *http.Request) {
			model.HandleCommands(w, r, db)
		})
	http.HandleFunc("/f",
		func(w http.ResponseWriter, r *http.Request) {
			model.HandleFeed(w, r, db)
		})
	http.Handle("/",
		http.FileServer(http.Dir("/opt/local/apache2/"+web_root+"/")))
	log.Fatal(http.ListenAndServe(":"+web_port, nil))
}
Exemplo n.º 2
0
func main() {
	flag.Parse()

	if *num_cpu == 0 {
		*num_cpu = runtime.NumCPU()
	}
	log.Printf("Cpus: %d\n", runtime.GOMAXPROCS(*num_cpu))

	if *static_root == "" {
		log.Fatal("Must pass --static_root")
	}
	if *orig_root == "" {
		log.Fatal("Must pass --orig_root")
	}
	if *root == "" {
		log.Fatal("Must pass --root")
	}
	db := model.NewDatabase2(*orig_root, *root)
	db.Load(*update_db, *update_db, *force_reload)
	log.Printf("Serving...")

	http.HandleFunc(*url_prefix+"/q",
		func(w http.ResponseWriter, r *http.Request) {
			Log("/q", r)
			model.HandleQuery(w, r, db)
		})
	http.HandleFunc(*url_prefix+"/montage/",
		func(w http.ResponseWriter, r *http.Request) {
			Log("/montage", r)
			model.HandleMontage2(w, r, db)
		})
	http.HandleFunc(*url_prefix+"/viewer",
		func(w http.ResponseWriter, r *http.Request) {
			Log("/viewer", r)
			model.HandleCommands(w, r, db)
		})
	http.Handle(
		*url_prefix+"/mini/",
		LogHandler(
			"/mini",
			http.StripPrefix(*url_prefix, http.FileServer(http.Dir(*root)))))
	http.Handle(
		*url_prefix+"/midi/",
		LogHandler(
			"/midi",
			http.StripPrefix(*url_prefix, http.FileServer(http.Dir(*root)))))
	http.Handle(
		*url_prefix+"/maxi/",
		LogHandler(
			"/maxi",
			http.StripPrefix(*url_prefix, http.FileServer(http.Dir(*root)))))
	http.Handle("/",
		LogHandler(
			"/ default",
			http.FileServer(http.Dir(*static_root+"/"))))

	for {
		err := http.ListenAndServe(":"+*port, nil)
		log.Printf("Web server error: %s\n", err)
	}
}