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") +}