init.go 908 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package v1
  4. import pb_v1 "lift-monitor/pb/v1"
  5. var snKey map[string]*pb_v1.DeviceInfoReply
  6. // 初始化map
  7. func Init() {
  8. snKey = make(map[string]*pb_v1.DeviceInfoReply)
  9. }
  10. /*
  11. // 获取key
  12. func GetKey(sn string) (*pb_v1.DeviceInfoReply, error) {
  13. if value, ok := snKey[sn]; ok {
  14. return value, nil
  15. }
  16. reply, err := GetDeviceInfo(sn)
  17. if err == nil {
  18. snKey[sn] = reply
  19. }
  20. return reply, err
  21. }
  22. // 从数据库中获取key
  23. func GetDeviceInfo(sn string) (*pb_v1.DeviceInfoReply, error) {
  24. req := &pb_v1.DeviceInfoRequest{Sn: sn, DeviceCode: consts.DustDeviceCode}
  25. reply, err := pb.SmartAuth.DeviceInfo(context.Background(), req)
  26. if err != nil {
  27. logger.Error("func",
  28. zap.String("call", "DeviceInfo"),
  29. zap.String("args", sn),
  30. zap.String("error", err.Error()))
  31. }
  32. return reply, err
  33. }
  34. */