🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
~~~ package main import ( "context" "fmt" hello "github.com/micro/go-grpc/examples/greeter/server/proto/hello" "github.com/micro/go-micro" "github.com/micro/go-micro/registry" "github.com/micro/go-plugins/registry/consul" ) func main() { reg := consul.NewRegistry(func(op *registry.Options) { op.Addrs = []string{ "123.207.79.96:8500", } }) service := micro.NewService( micro.Name("go.micro.srv.greeter"), micro.Registry(reg), ) service.Init() cl := hello.NewSayService("go.micro.srv.greeter", service.Client()) rsp, err := cl.Hello(context.TODO(), &hello.Request{ Name: "John", }) if err != nil { fmt.Println(err) return } fmt.Println(rsp.Msg) } ~~~