micro/service/grpc/examples/greeter/client/main.go
2019-06-03 18:44:43 +01:00

41 lines
681 B
Go

package main
import (
"context"
"fmt"
"github.com/micro/cli"
"github.com/micro/go-micro"
"github.com/micro/go-micro/service/grpc"
hello "github.com/micro/go-micro/service/grpc/examples/greeter/server/proto/hello"
)
var (
// service to call
serviceName string
)
func main() {
service := grpc.NewService()
service.Init(
micro.Flags(cli.StringFlag{
Name: "service_name",
Value: "go.micro.srv.greeter",
Destination: &serviceName,
}),
)
cl := hello.NewSayService(serviceName, service.Client())
rsp, err := cl.Hello(context.TODO(), &hello.Request{
Name: "John",
})
if err != nil {
fmt.Println(err)
return
}
fmt.Println(rsp.Msg)
}