12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- 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 r.client != nil && r.client.Conn() != nil {
- return r.client
- }
- client, err := zrpc.NewClient(zrpc.RpcClientConf{
- Etcd: discov.EtcdConf{
- Hosts: p.hosts,
- Key: p.key,
- },
- })
- if err != nil {
- log.Println(err)
- return nil
- }
- r.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
- }
|