|
|
@ -5,8 +5,8 @@ import ( |
|
|
|
"log" |
|
|
|
"log" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/go-kratos/etcd/registry" |
|
|
|
"github.com/go-kratos/etcd/registry" |
|
|
|
pb "github.com/go-kratos/kratos/examples/helloworld/helloworld" |
|
|
|
"github.com/go-kratos/kratos/examples/helloworld/helloworld" |
|
|
|
transgrpc "github.com/go-kratos/kratos/v2/transport/grpc" |
|
|
|
"github.com/go-kratos/kratos/v2/transport/grpc" |
|
|
|
clientv3 "go.etcd.io/etcd/client/v3" |
|
|
|
clientv3 "go.etcd.io/etcd/client/v3" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
@ -18,16 +18,16 @@ func main() { |
|
|
|
panic(err) |
|
|
|
panic(err) |
|
|
|
} |
|
|
|
} |
|
|
|
r := registry.New(cli) |
|
|
|
r := registry.New(cli) |
|
|
|
conn, err := transgrpc.DialInsecure( |
|
|
|
conn, err := grpc.DialInsecure( |
|
|
|
context.Background(), |
|
|
|
context.Background(), |
|
|
|
transgrpc.WithEndpoint("discovery://d/helloworld"), |
|
|
|
grpc.WithEndpoint("discovery:///helloworld"), |
|
|
|
transgrpc.WithDiscovery(r), |
|
|
|
grpc.WithDiscovery(r), |
|
|
|
) |
|
|
|
) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Fatal(err) |
|
|
|
log.Fatal(err) |
|
|
|
} |
|
|
|
} |
|
|
|
client := pb.NewGreeterClient(conn) |
|
|
|
client := helloworld.NewGreeterClient(conn) |
|
|
|
reply, err := client.SayHello(context.Background(), &pb.HelloRequest{Name: "kratos"}) |
|
|
|
reply, err := client.SayHello(context.Background(), &helloworld.HelloRequest{Name: "kratos"}) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Fatal(err) |
|
|
|
log.Fatal(err) |
|
|
|
} |
|
|
|
} |
|
|
|