我已经从 github 克隆了这个项目:https://github.com/gustavohenrique/grpc-web-golang-vuejs/tree/master/backend。 我运行了前端和后端的项目。它有效。 该项目使用 grpcweb 包装服务器。 然后我写了一个小客户端来调用grpc服务器函数但是它不起作用。 我的客户端代码如下所示..
package main
import (
"context"
"fmt"
"io"
"log"
"time"
pb "backend/proto"
"google.golang.org/grpc"
)
func main() {
fmt.Println("Hello I'm a client")
conn, err := grpc.Dial("0.0.0.0:9000", grpc.WithInsecure())
if err != nil {
log.Fatalf("could not connect: %v", err)
}
defer conn.Close()
c := pb.NewAccountServiceClient(conn)
)
doUnary(c)
}
func doUnary(c pb.AccountServiceClient) {
fmt.Println("do unary from the client")
req := &pb.User{
Email: "hh1212",
Password: "23123",
}
res, err := c.Create(context.Background(), req)
if err != nil {
log.Fatalf("error while calling RPC: %v", err)
}
log.Printf("Response from Greet: %v", res.GetEmail())
}
现在,当我运行此代码时,它会返回此错误:
code = Unavailable desc = connection closed
exit status 1
grpcweb 包裹服务器的功能和普通的 grpc 服务器一样吗?或者我们有什么不同的东西可以从客户端进行通信? 戈兰