func main() {
	flag.Usage = usage
	flag.Parse()
	if *help {
		flag.Usage()
		return
	}

	var opts []grpc.DialOption
	// Note that this is not secure.
	opts = append(opts, grpc.WithInsecure())

	// Create connection
	conn, err := grpc.Dial(*endpoint, opts...)
	if err != nil {
		fmt.Printf("Error while connecting to server: %v\n", err)
		return
	}
	defer conn.Close()
	fmt.Printf("Connected to server on %v\n", *endpoint)

	// Create client
	client := apProto.NewApClient(conn)

	labs := []*apProto.ApRequestLab{
		&apProto.ApRequestLab{Name: "lab1", Language: int32(C)},
		&apProto.ApRequestLab{Name: "lab2", Language: int32(Golang)}}

	// Create request
	request := apProto.ApRequest{GithubOrg: "test-repo",
		GithubToken:  "testtoken",
		StudentRepos: []string{"student1-labs", "student2-labs"},
		Labs:         labs}

	// Send request and get response
	response, err := client.CheckPlagiarism(context.Background(), &request)

	// Check response
	if err != nil {
		fmt.Printf("gRPC error: %s\n", err)
	} else if response.Success == false {
		fmt.Printf("Anti-plagiarism error: %s\n", response.Err)
	} else {
		fmt.Printf("Anti-plagiarism application received request.\n")
	}
}
示例#2
0
// callAntiplagiarism sends a request to the anti-plagiarism software.
// It takes as input request, an ApRequest (anti-plagiarism request),
// org, a database record for the class, and isGroup, whether or not
// the request if for individual or group assignments.
func callAntiplagiarism(request apProto.ApRequest, org *git.Organization, isGroup bool) {
	// Currently just on localhost.
	// TODO: Remove hard-coded value
	endpoint := "localhost:11111"
	var opts []grpc.DialOption
	// TODO: Add transport security.
	opts = append(opts, grpc.WithInsecure())

	// Create connection
	conn, err := grpc.Dial(endpoint, opts...)
	if err != nil {
		fmt.Printf("callAntiplagiarism: Error while connecting to server: %v\n", err)
		return
	}
	defer conn.Close()
	fmt.Printf("Connected to server on %v\n", endpoint)

	// Create client
	client := apProto.NewApClient(conn)

	// Send request and get response
	fmt.Printf("Sending request to anti-plagiarism application.\n")
	response, err := client.CheckPlagiarism(context.Background(), &request)

	// Check response
	if err != nil {
		fmt.Printf("callAntiplagiarism: gRPC error: %s\n", err)
		return
	} else if response.Success == false {
		fmt.Printf("callAntiplagiarism: Anti-plagiarism error: %s\n", response.Err)
		return
	} else {
		fmt.Printf("Anti-plagiarism application ran successfully.\n")
	}

	clearPreviousResults(org, isGroup)
	saveNewResults(org, isGroup)
}