예제 #1
0
func main() {
	flag.Parse()

	log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds | log.Lshortfile)

	analyzers := []api.Analyzer{
		new(postmessage.PostMessageAnalyzer),
		new(wordcount.WordCountAnalyzer),
		new(jshint.JSHintAnalyzer),
		new(codealert.CodeAlertAnalyzer),
		new(pylint.PyLintAnalyzer),
		new(govet.GoVetAnalyzer),
	}
	analyzerService := api.CreateAnalyzerService(analyzers, ctxpb.Stage_PRE_BUILD)

	s1 := server.Service{Name: "AnalyzerService"}
	if err := s1.Register(analyzerService); err != nil {
		log.Fatalf("Registering analyzer service failed: %v", err)
	}

	addr := fmt.Sprintf(":%d", *servicePort)

	log.Printf("-- Starting server endpoint at %q", addr)

	http.Handle("/", server.Endpoint{&s1})

	if err := http.ListenAndServe(addr, nil); err != nil {
		log.Fatalf("Server startup failed: %v", err)
	}
}
예제 #2
0
func CreatekRPCTestServer(dispatcher interface{}, name string) (string, func(), error) {
	kRPCServer := server.Service{Name: name}
	if err := kRPCServer.Register(dispatcher); err != nil {
		return "", nil, err
	}
	testServer := httptest.NewServer(server.Endpoint{&kRPCServer})
	cleanup := func() {
		testServer.CloseClientConnections()
		testServer.Close()
	}

	return testServer.URL, cleanup, nil
}
예제 #3
0
func main() {
	flag.Parse()

	// The shipshape service will connect to an AnalyzerService
	// at port 10005 in the container. (The service will map this to a different external
	// port at startup so that it doesn't clash with other analyzers.)
	s := server.Service{Name: "AnalyzerService"}
	as := api.CreateAnalyzerService([]api.Analyzer{new(androidlint.Analyzer)}, ctxpb.Stage_PRE_BUILD)
	if err := s.Register(as); err != nil {
		log.Fatalf("Registering analyzer service failed: %v", err)
	}

	addr := fmt.Sprintf(":%d", *servicePort)
	fmt.Fprintf(os.Stderr, "-- Starting server endpoint at %q\n", addr)
	http.Handle("/", server.Endpoint{&s})

	if err := http.ListenAndServe(addr, nil); err != nil {
		log.Fatalf("Server startup failed: %v", err)
	}
}
예제 #4
0
파일: shipshape.go 프로젝트: nrc/shipshape
func main() {
	flag.Parse()

	log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds | log.Lshortfile)
	analyzerList := strings.Split(*analyzers, ",")

	log.Printf("Waiting for analyzers to become healthy...")
	healthErrors := service.WaitForAnalyzers(analyzerList)
	allHealthy := true
	for addr, err := range healthErrors {
		if err != nil {
			log.Printf("Analyzer at %s failed to become healthy: %v", addr, err)
			allHealthy = false
		} else {
			log.Printf("Analyzer at %s registered", addr)
		}
	}
	if allHealthy {
		log.Printf("All analyzers deemed healthy")
	}

	shipshapeService := service.NewDriver(analyzerList)

	if *startService {
		// Start shipshape service
		s1 := server.Service{Name: serviceName}
		if err := s1.Register(shipshapeService); err != nil {
			log.Fatalf("Registering shipshape service failed: %v", err)
		}
		addr := fmt.Sprintf(":%d", *servicePort)
		log.Printf("Starting server endpoint at %q with service name %s\n", addr, serviceName)
		http.Handle("/", server.Endpoint{&s1})
		if err := http.ListenAndServe(addr, nil); err != nil {
			log.Fatalf("Server startup failed: %v", err)
		}
	} else {
		log.Println("Waiting for stdin. Specify --start_service if you meant to start as a service.")

		// Read request bytes from stdin
		requestBytes, err := ioutil.ReadAll(os.Stdin)
		if err != nil {
			log.Fatal("failed to read stdin: ", err)
		}

		log.Printf("Read shipshape request on stdin [%v bytes]", len(requestBytes))

		// Convert bytes from stdin to Shipshape request
		request := new(rpcpb.ShipshapeRequest)
		err = proto.Unmarshal(requestBytes, request)
		if err != nil {
			log.Fatal("failed to unmarshal shipshape request stream: ", err)
		}

		c := make(chan *rpcpb.ShipshapeResponse)

		go func() {
			if err := shipshapeService.Run(nil, request, c); err != nil {
				log.Printf("Failed to run on server: %v", err)
			}
		}()

		log.Print("Sent request to driver")

		response := <-c

		log.Printf("Shipshape response: [%s]", response)

		responseBytes, err := proto.Marshal(response)
		if err != nil {
			log.Fatal("failed to marshal shipshape response: ", err)
		}

		log.Printf("Writing Shipshape response to stdout")

		os.Stdout.Write(responseBytes)
	}
}