Sobes.tech
Junior — Middle

Describe the process of collecting and setting up a gRPC service for manual testing or development.

sobes.tech AI

Answer from AI

For manual testing or development of a gRPC service in Go, the following steps are usually performed:

  1. Define the protocol — write a .proto file describing the services and messages.

  2. Generate code — use protoc and the protoc-gen-go plugin to generate Go code for the server and client parts:

protoc --go_out=. --go-grpc_out=. service.proto
  1. Implement the server — create a structure that implements the generated service interfaces.

  2. Configure the server — set up the port, middleware (logging, authentication) if necessary.

  3. Start the server — run the server in a separate process or in the background.

  4. Manual testing:

    • Use grpcurl or evans to call service methods from the command line.
    • Write a simple client in Go or another language for verification.

Example of starting the server:

lis, err := net.Listen("tcp", ":50051")
if err != nil {
    log.Fatalf("failed to listen: %v", err)
}
s := grpc.NewServer()
pb.RegisterYourServiceServer(s, &server{})
if err := s.Serve(lis); err != nil {
    log.Fatalf("failed to serve: %v", err)
}

For development, it is convenient to use hot reload and logging for quick testing cycles.