feat(external-gateway): add external gateway call

This commit is contained in:
bandl 2021-11-16 00:17:47 +08:00
parent 60cf8f5eb1
commit d68209c94c
2 changed files with 36 additions and 0 deletions

12
storage/external/define.go vendored Normal file
View File

@ -0,0 +1,12 @@
package external
import (
"sync"
"gitee.com/wheat-os/wheatCache/pkg/proto"
)
var (
oneGatewayClient sync.Once
gatewayClient proto.CommServerClient
)

24
storage/external/gateway.go vendored Normal file
View File

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