From d68209c94ccd32c6bf3fd2049308a360aac86bfd Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Tue, 16 Nov 2021 00:17:47 +0800 Subject: [PATCH] feat(external-gateway): add external gateway call --- storage/external/define.go | 12 ++++++++++++ storage/external/gateway.go | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 storage/external/define.go create mode 100644 storage/external/gateway.go diff --git a/storage/external/define.go b/storage/external/define.go new file mode 100644 index 0000000..af328de --- /dev/null +++ b/storage/external/define.go @@ -0,0 +1,12 @@ +package external + +import ( + "sync" + + "gitee.com/wheat-os/wheatCache/pkg/proto" +) + +var ( + oneGatewayClient sync.Once + gatewayClient proto.CommServerClient +) diff --git a/storage/external/gateway.go b/storage/external/gateway.go new file mode 100644 index 0000000..3b8fe63 --- /dev/null +++ b/storage/external/gateway.go @@ -0,0 +1,24 @@ +package external + +import ( + "errors" + + "gitee.com/wheat-os/wheatCache/client" + "gitee.com/wheat-os/wheatCache/client/middle" + "gitee.com/wheat-os/wheatCache/pkg/proto" +) + +func NewGatewayClient() (proto.CommServerClient, error) { + oneGatewayClient.Do(func() { + cli, err := client.NewWheatClient("127.0.0.1:5891", middle.WithUnaryColonyClient) + if err == nil { + gatewayClient = cli + } + }) + + if gatewayClient != nil { + return gatewayClient, nil + } + + return nil, errors.New("get gateway err") +}