{"id":"go.micro.client.transport","code":500,"detail":"malformed HTTP response \"\\x00\\x00\\x06\\x04\\x00\\x00\\x00\\x00\\x00\\x00\\x05\\x00\\x00@\\x00\"","status":"Internal Server Error"}
<nil>
Press Enter key to exit the program...
^Csignal: interrupt
解决方案
重点在于下面代码的第12
行和第19
行:
package main
import (
"bufio"
"context"
"fmt"
pb "go_technology_stack/demos/hello_go_micro/pb"
"os"
regConsul "github.com/go-micro/plugins/v4/registry/consul"
"github.com/go-micro/plugins/v4/client/grpc"
"go-micro.dev/v4"
"go-micro.dev/v4/registry"
)
func main() {
service := micro.NewService(
micro.Client(grpc.NewClient()),
micro.Registry(regConsul.NewRegistry(
registry.Addrs("192.168.1.99:8500"),
)), // 添加consul作为注册中心
)
service.Init()
client := pb.NewHelloService("rpchello.service", service.Client())
rsp, err := client.SayHello(context.TODO(), &pb.SayHelloReq{})
if err != nil {
fmt.Println(err)
}
fmt.Println(rsp)
fmt.Println("Press Enter key to exit the program...")
in := bufio.NewReader(os.Stdin)
_, _, _ = in.ReadLine()
}