12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package util
- import (
- "context"
- "dust-monitor/consts"
- "dust-monitor/pb"
- pb_v1 "dust-monitor/pb/v1"
- "github.com/jaryhe/gopkgs/logger"
- "go.uber.org/zap"
- )
- var snKey map[string]*pb_v1.DeviceInfoReply
- // 初始化map
- func Init() {
- snKey = make(map[string]*pb_v1.DeviceInfoReply)
- }
- // 获取key
- func GetKey(sn string) (*pb_v1.DeviceInfoReply, error) {
- if value, ok := snKey[sn]; ok {
- return value, nil
- }
- reply, err := GetDeviceInfo(sn)
- if err == nil {
- snKey[sn] = reply
- }
- return reply, err
- }
- // 从数据库中获取key
- func GetDeviceInfo(sn string) (*pb_v1.DeviceInfoReply, error) {
- req := &pb_v1.DeviceInfoRequest{Sn: sn, DeviceCode: consts.DustDeviceCode}
- reply, err := pb.SmartAuth.DeviceInfo(context.Background(), req)
- if err != nil {
- logger.Error("func",
- zap.String("call", "pb.SmartAuth.DeviceInfo"),
- zap.String("args", sn),
- zap.String("error", err.Error()))
- }
- return reply, err
- }
- func GetDustSns()(*pb_v1.GetAllDustSnReply, error) {
- req := &pb_v1.GetAllDustSnRequest{}
- reply, err := pb.SmartAuth.GetAllDustSn(context.Background(), req)
- if err != nil {
- logger.Error("func",
- zap.String("call", "pb.SmartAuth.GetAllDustSn"),
- zap.String("error", err.Error()))
- }
- return reply, err
- }
|