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:
-
Define the protocol — write a
.protofile describing the services and messages. -
Generate code — use
protocand theprotoc-gen-goplugin to generate Go code for the server and client parts:
protoc --go_out=. --go-grpc_out=. service.proto
-
Implement the server — create a structure that implements the generated service interfaces.
-
Configure the server — set up the port, middleware (logging, authentication) if necessary.
-
Start the server — run the server in a separate process or in the background.
-
Manual testing:
- Use
grpcurlorevansto call service methods from the command line. - Write a simple client in Go or another language for verification.
- Use
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.