package middleground import ( "context" "log" "bp.jydev.jianyu360.cn/BaseService/powerCheckCenter/rpc/pb" "bp.jydev.jianyu360.cn/BaseService/powerCheckCenter/rpc/powercheck" "github.com/zeromicro/go-zero/core/discov" "github.com/zeromicro/go-zero/zrpc" ) type powerCheckCenter struct { hosts []string key string client zrpc.Client } func newPowerCheckCenter(hosts []string, key string) *powerCheckCenter { r := &powerCheckCenter{ hosts: hosts, key: key, } r.client = r.NewClient() return r } func (p *powerCheckCenter) NewClient() zrpc.Client { if p.client != nil && p.client.Conn() != nil { return p.client } client, err := zrpc.NewClient(zrpc.RpcClientConf{ Etcd: discov.EtcdConf{ Hosts: p.hosts, Key: p.key, }, }) if err != nil { log.Println(err) return nil } p.client = client return client } func (p *powerCheckCenter) Check(appid, userId string, baseUserId, accountId, entId, positionType, positionId int64) *pb.CheckResp { client := p.NewClient() if client == nil { return nil } //defer client.Conn().Close() resp, err := powercheck.NewPowerCheck(client).Check(context.Background(), &pb.CheckReq{ Appid: appid, Userid: userId, BaseUserId: baseUserId, AccountId: accountId, EntId: entId, PositionType: positionType, PositionId: positionId, }) if err != nil { log.Println(err) return nil } return resp } func (p *powerCheckCenter) DelCheckRedis(appid string, positionId int64) *pb.PowerCheckResp { client := p.NewClient() if client == nil { return nil } //defer client.Conn().Close() resp, err := powercheck.NewPowerCheck(client).DelCheckRedis(context.Background(), &pb.CheckReq{ Appid: appid, PositionId: positionId, }) if err != nil { log.Println(err) return nil } return resp }