多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
~~~ 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) } ~~~