fix:etcd<3.13 block question (#1317)

pull/1320/head
月墨夕 3 years ago committed by GitHub
parent 6d06721fc8
commit 6ae2e8712d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      examples/go.mod
  2. 4
      examples/go.sum
  3. 42
      examples/registry/etcd/client/main.go

@ -8,7 +8,7 @@ require (
github.com/envoyproxy/protoc-gen-validate v0.6.1
github.com/gin-gonic/gin v1.7.3
github.com/go-kratos/consul v0.1.4
github.com/go-kratos/etcd v0.1.2
github.com/go-kratos/etcd v0.1.3
github.com/go-kratos/gin v0.1.0
github.com/go-kratos/kratos/v2 v2.0.3
github.com/go-kratos/nacos v0.1.1

@ -178,8 +178,8 @@ github.com/go-kratos/consul v0.1.2/go.mod h1:FhxdCfkqaqIYfgpGbzGb8ywM/zV3jk+EBS+
github.com/go-kratos/consul v0.1.4 h1:qOOQE/FYpbWLV4cipC+jPrrc/gQY1DdfnX0IJvQleXE=
github.com/go-kratos/consul v0.1.4/go.mod h1:egsB9apqg+4BMYVnY/VuQCeC3aAmd7mpYfIMhs4ga4U=
github.com/go-kratos/etcd v0.1.0/go.mod h1:RzWYbka3LjS0v2RbCtADN7d2Ng8eH774ehHlTGgbma4=
github.com/go-kratos/etcd v0.1.2 h1:/thmpcEUleRro1bbRN3NfJHFwYzjVvbojvQv1QKGljg=
github.com/go-kratos/etcd v0.1.2/go.mod h1:+MGVcBnNfpiZ2kw05P/m0ijKNLhRz1p0HXWJhO85AJI=
github.com/go-kratos/etcd v0.1.3 h1:ARz1j4nZGgpeSw8WYau5y8LiKbsty/tMASQCaiOGZnM=
github.com/go-kratos/etcd v0.1.3/go.mod h1:4UAwbmm/PIjUS9KwhqmfsBi9pksuvwc3ae+xaKF0Lwk=
github.com/go-kratos/gin v0.1.0 h1:yq5GfZnSNo8cOIqxqPE0FVNQ8fm++oKQBd3/rTTp4oI=
github.com/go-kratos/gin v0.1.0/go.mod h1:KzE88+mV1QJdmiT+sU2D560ucOXnWZx+4m0OnVcSyzQ=
github.com/go-kratos/grpc-gateway/v2 v2.0.0-20210804092615-bdc92eb5ce83 h1:YN1KsqX3mB8hkSrOLZv3xZaZh+lZ/L7QC00RATFLJSg=

@ -10,6 +10,7 @@ import (
"github.com/go-kratos/kratos/v2/transport/grpc"
"github.com/go-kratos/kratos/v2/transport/http"
clientv3 "go.etcd.io/etcd/client/v3"
srcgrpc "google.golang.org/grpc"
)
func main() {
@ -20,15 +21,8 @@ func main() {
panic(err)
}
r := registry.New(cli)
for {
callHTTP(r)
callGRPC(r)
time.Sleep(time.Second)
}
}
func callGRPC(r *registry.Registry) {
conn, err := grpc.DialInsecure(
connGrpc, err := grpc.DialInsecure(
context.Background(),
grpc.WithEndpoint("discovery:///helloworld"),
grpc.WithDiscovery(r),
@ -36,17 +30,9 @@ func callGRPC(r *registry.Registry) {
if err != nil {
log.Fatal(err)
}
defer conn.Close()
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)
}
defer connGrpc.Close()
func callHTTP(r *registry.Registry) {
conn, err := http.NewClient(
connHttp, err := http.NewClient(
context.Background(),
http.WithEndpoint("discovery:///helloworld"),
http.WithDiscovery(r),
@ -55,7 +41,25 @@ func callHTTP(r *registry.Registry) {
if err != nil {
log.Fatal(err)
}
defer conn.Close()
defer connHttp.Close()
for {
callHTTP(r, connHttp)
callGRPC(r, connGrpc)
time.Sleep(time.Second)
}
}
func callGRPC(r *registry.Registry, conn *srcgrpc.ClientConn) {
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)
}
func callHTTP(r *registry.Registry,conn *http.Client) {
client := helloworld.NewGreeterHTTPClient(conn)
reply, err := client.SayHello(context.Background(), &helloworld.HelloRequest{Name: "kratos"})
if err != nil {

Loading…
Cancel
Save