Пример #1
0
func main() {
	flag.Parse()
	if flag.NArg() < 1 {
		fmt.Println("use:  pi <command> [command args]")
		return
	}

	p, err := pisearch.Open(*piFile)
	if err != nil {
		log.Fatal("Could not open", *piFile, ":", err)
	}

	switch flag.Arg(0) {
	case "search":
		do_search(p)
	case "analyze":
		do_analyze(p)
	case "count":
		do_count(p)
	}
	p.Close()
}
Пример #2
0
func main() {
	pisearch, err := pisearch.Open(pifile)
	if err != nil {
		log.Fatal("Could not open ", pifile, ": ", err)
	}
	logfile, err = os.OpenFile(LOGFILE, syscall.O_RDWR|syscall.O_CREAT, 0644)
	if err != nil {
		logfile = nil
	}
	server := &Piserver{pisearch, logfile}
	http.Handle("/piquery",
		jsonhandler(func(req *http.Request, respmap map[string]interface{}) {
			server.ServeQuery(req, respmap)
		}))
	http.Handle("/pidigits",
		jsonhandler(func(req *http.Request, respmap map[string]interface{}) {
			server.ServeDigits(req, respmap)
		}))

	werr := http.ListenAndServe(":1415", nil)
	if werr != nil {
		log.Fatal("ListenAndServe: ", err)
	}
}