1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package utils
- import (
- "access-control-monitor/consts"
- "access-control-monitor/pb"
- pb_v1 "access-control-monitor/pb/v1"
- "context"
- "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.AccessControlDeviceCode}
- reply, err := pb.Auth.DeviceInfo(context.Background(), req)
- if err != nil {
- logger.Error("func",
- zap.String("call", "DeviceInfo"),
- zap.String("args", sn),
- zap.String("error", err.Error()))
- }
- return reply, err
- }
|