我用 grpc-gateway 创建了一个基本服务。这就是我的 .proto 文件的样子
syntax = "proto3";
package health;
option go_package = "github.com/userl/brw/api/health";
import "google/api/annotations.proto";
service Health {
// Sends a greeting
rpc Ping (HealthRequest) returns (HealthReply) {
option (google.api.http) = {
get: "/ping"
};
}
}
// The request message containing the user's name
message HealthRequest {
}
// The response message containing the greetings
message HealthReply {
string message = 1;
}
我使用以下代码生成并启动服务
mux := runtime.NewServeMux()
opts := []grpc.DialOption{grpc.WithInsecure()}
err := pHealth.RegisterHealthHandlerFromEndpoint(ctx, mux, ":3002"), opts)
if err != nil {
log.Fatal(err)
}
http.ListenAndServe(":3001"), mux)
现在,当我尝试 curl 命令时,例如,
curl http://localhost:3001/ping
我收到以下错误
curl: (7) Failed to connect to localhost port 3003: Connection refused
当我尝试 grpcurl 时
grpcurl --plaintext localhost:3002 list
,出现以下错误
failed to dial target host "localhost:3002": dial tcp 127.0.0.1:3002: connect: connection refused
不知道这里出了什么问题或我需要做什么。