func main() { if *httpAddr != "" { serveHTTP(*httpAddr) return } if flag.NArg() == 0 { PrintHelp(pkg, version, about, usage) os.Exit(0) } nmatches := 0 for _, method := range strings.Split(*searchMethod, ",") { var err error ch := make(chan string) go func() { err = locate.Locate(db, method, flag.Arg(0), ch) }() for m := range ch { nmatches++ fmt.Println(m) } if err != nil { log.Fatal(err) } if nmatches > 0 { break } } }
func handler(w http.ResponseWriter, r *http.Request) { pattern := r.URL.Path[1:] if pattern == "" { printConfig(w) return } w.Header().Set("Content-Type", "text/html") nmatches := 0 for _, method := range strings.Split(*searchMethod, ",") { var err error ch := make(chan string) go func() { err = locate.Locate(db, method, pattern, ch) }() for p := range ch { nmatches++ m := &Match{Path: p, Base: filepath.Base(p), N: nmatches} tpl.Execute(w, m) } if err != nil { fmt.Println(w, err) return } if nmatches > 0 { break } } }