You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
743 B
33 lines
743 B
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
|
|
"github.com/go-kratos/consul/registry"
|
|
"github.com/go-kratos/kratos/examples/helloworld/helloworld"
|
|
"github.com/go-kratos/kratos/v2/transport/grpc"
|
|
"github.com/hashicorp/consul/api"
|
|
)
|
|
|
|
func main() {
|
|
cli, err := api.NewClient(api.DefaultConfig())
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
r := registry.New(cli)
|
|
conn, err := grpc.DialInsecure(
|
|
context.Background(),
|
|
grpc.WithEndpoint("discovery:///helloworld"),
|
|
grpc.WithDiscovery(r),
|
|
)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
client := helloworld.NewGreeterClient(conn)
|
|
reply, err := client.SayHello(context.Background(), &helloworld.HelloRequest{Name: "kratos"})
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
log.Printf("[grpc] SayHello %+v\n", reply)
|
|
}
|
|
|