An overview of the

I have been busy with my work recently. I found that I haven’t written any more in 3 weeks.

Thank you for being here, today to share a gRPC debugging tool.

Let’s get down to business.

When we write HTTP interface, we use Postman for interface debugging, so when writing gRPC interface, is there a debugging tool similar to Postman?

There is.

Let’s look at grpCUI, source code address:

Github.com/fullstoryde…

Check out the official description:

grpcui is a command-line tool that lets you interact with gRPC servers via a browser. It’s sort of like Postman, but for gRPC APIs instead of REST.

Write a gRPC API

I wrote a Demo before, so I can just use the listen project that I wrote before.

Port: 9901

Proto file:

syntax = "proto3"; // Specify proto version package listen; Service Listen {// Define the method RPC ListenData(Request) returns (Response) {}} // Request Request structure Message Request  { string name = 1; Message Response {string message = 1; }Copy the code

It’s easy. You can see that.

  • The Service name to listen. Listen
  • The Method name for ListenData

Look again at the ListenData method:

func (l *ListenController) ListenData(ctx context.Context, in *listen.Request) (*listen.Response, error) {
	return &listen.Response{Message : fmt.Sprintf("[%s]", in.Name)}, nil
}
Copy the code

So that means I’m going to return Name directly.

Source code address:

Github.com/xinliangnot…

Start the service

cd listen && go run main.go
Copy the code

After the service is successfully started, wait to use it.

Grpcui use

The installation

Install it according to the official readme. md document.

go get github.com/fullstorydev/grpcui
go install github.com/fullstorydev/grpcui/cmd/grpcui
Copy the code

At this point, a GrpCUI executable is generated in the $GOPATH/bin directory.

Run the following command to verify:

grpcui -help
Copy the code

Output:

Usage:
	grpcui [flags] [address]
	
......	
Copy the code

The installation is successful.

run

Grpcui-plaintext 127.0.0.1:9901 Failed to compute set of methods to expose: Server does not support the Reflection APICopy the code

In this case, add a reflection. Add the following code to listen main.go:

reflection.Register(s)
Copy the code

Try it once before running:

Grpcui-plaintext 127.0.0.1:9901 gRPC Web UI available at http://127.0.0.1:63027/Copy the code

Visit http://127.0.0.1:63027/ in your browser

Method name = Method name = Method name = Method name = Method name = Method name

When you send a Request “Tom”, you can also get a Response “Tom”.

If there are more than one Service name, the Method name will also be displayed.

Go-gin-api series of articles

  • 7. Routing middleware – Signature verification
  • 6. Routing Middleware – Jaeger Link Tracing
  • 5. Routing Middleware – Jaeger Link Tracing (Theory)
  • 4. Routing middleware – Catch exceptions
  • 3. Routing middleware – logging
  • 2. Plan the project catalog and verify parameters
  • 1. Initialize the project using Go Modules