コード例 #1
0
ファイル: source-backend.go プロジェクト: Debian/dcs
func main() {
	flag.Parse()
	rand.Seed(time.Now().UnixNano())
	if !strings.HasSuffix(*unpackedPath, "/") {
		*unpackedPath = *unpackedPath + "/"
	}
	fmt.Println("Debian Code Search source-backend")

	if err := ranking.ReadRankingData(*rankingDataPath); err != nil {
		log.Fatal(err)
	}

	conn, err := grpcutil.DialTLS("localhost:28081", *tlsCertPath, *tlsKeyPath)
	if err != nil {
		log.Fatalf("could not connect to %q: %v", "localhost:28081", err)
	}
	defer conn.Close()
	indexBackend = proto.NewIndexBackendClient(conn)

	http.Handle("/metrics", prometheus.Handler())
	log.Fatal(grpcutil.ListenAndServeTLS(*listenAddress,
		*tlsCertPath,
		*tlsKeyPath,
		func(s *grpc.Server) {
			proto.RegisterSourceBackendServer(s, &server{})
		}))
}
コード例 #2
0
ファイル: importer.go プロジェクト: Debian/dcs
func main() {
	flag.Parse()

	// Allow as many concurrent unpackAndIndex goroutines as we have cores.
	runtime.GOMAXPROCS(runtime.NumCPU())

	if err := os.MkdirAll(*unpackedPath, 0755); err != nil {
		log.Fatal(err)
	}

	setupFilters()

	var err error
	tmpdir, err = ioutil.TempDir("", "dcs-importer")
	if err != nil {
		log.Fatal(err)
	}

	indexQueue = make(chan string)
	mergeQueue = make(chan bool)

	for i := 0; i < runtime.NumCPU(); i++ {
		go unpackAndIndex()
	}

	go func() {
		for _ = range mergeQueue {
			mergeToShard()
		}
	}()

	conn, err := grpcutil.DialTLS("localhost:28081", *tlsCertPath, *tlsKeyPath)
	if err != nil {
		log.Fatalf("could not connect to %q: %v", "localhost:28081", err)
	}
	defer conn.Close()
	indexBackend = proto.NewIndexBackendClient(conn)

	http.HandleFunc("/import/", importPackage)
	http.HandleFunc("/merge", mergeOrError)
	http.HandleFunc("/listpkgs", listPackages)
	http.HandleFunc("/garbagecollect", garbageCollect)
	http.HandleFunc("/goroutinez", goroutinez.Goroutinez)
	http.Handle("/metrics", prometheus.Handler())

	log.Fatal(http.ListenAndServe(*listenAddress, nil))
}