|
@@ -368,9 +368,7 @@ func (r *Registry) FindDeviceByIdentifier(identifier string, reply *models.Devic
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- var storage models.Device
|
|
|
|
- storage = *reply
|
|
|
|
- cache.Set(cacheKey, &storage)
|
|
|
|
|
|
+ cache.Set(cacheKey, &reply)
|
|
}
|
|
}
|
|
|
|
|
|
return nil
|
|
return nil
|
|
@@ -381,22 +379,20 @@ func (r *Registry) FindDeviceById(args uint64, reply *models.Device) error {
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- cache := getCache()
|
|
|
|
- key := fmt.Sprintf("Device:%v", args)
|
|
|
|
- if v, ok := cache.Get(key);ok {
|
|
|
|
- device := v.(*models.Device)
|
|
|
|
- setDevice(reply, device)
|
|
|
|
- fmt.Printf("%v\r\n", device)
|
|
|
|
- } else {
|
|
|
|
- d := &models.Device{}
|
|
|
|
- d.ID = uint(args)
|
|
|
|
- err = db.Where(d).First(reply).Error
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
- cache.Set(key, reply)
|
|
|
|
|
|
+ //cache := getCache()
|
|
|
|
+ //key := fmt.Sprintf("Device:%v", args)
|
|
|
|
+ //if v, ok := cache.Get(key);ok {
|
|
|
|
+ // device := v.(*models.Device)
|
|
|
|
+ // setDevice(reply, device)
|
|
|
|
+ //} else {
|
|
|
|
+ d := &models.Device{}
|
|
|
|
+ d.ID = uint(args)
|
|
|
|
+ err = db.Where(d).First(reply).Error
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ // cache.Set(key, reply)
|
|
|
|
+ //}
|
|
|
|
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
@@ -409,7 +405,7 @@ func (r *Registry) FindDeviceByRecordId(args *rpcs.ArgsDeviceAuth, reply *models
|
|
}
|
|
}
|
|
cache := getCache()
|
|
cache := getCache()
|
|
key := fmt.Sprintf("Device:%v", args.DeviceID)
|
|
key := fmt.Sprintf("Device:%v", args.DeviceID)
|
|
- if v, ok := cache.Get(key);ok {
|
|
|
|
|
|
+ if v, ok := cache.Get(key); ok {
|
|
device := v.(*models.Device)
|
|
device := v.(*models.Device)
|
|
setDevice(reply, device)
|
|
setDevice(reply, device)
|
|
} else {
|
|
} else {
|
|
@@ -424,12 +420,9 @@ func (r *Registry) FindDeviceByRecordId(args *rpcs.ArgsDeviceAuth, reply *models
|
|
cache.Set(key, &storage)
|
|
cache.Set(key, &storage)
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
// ValidateDevice will validate a device key and return the model if success.
|
|
// ValidateDevice will validate a device key and return the model if success.
|
|
func (r *Registry) ValidateDevice(key string, device *models.Device) error {
|
|
func (r *Registry) ValidateDevice(key string, device *models.Device) error {
|
|
id, err := r.keygen.DecodeIDFromRandomKey(key)
|
|
id, err := r.keygen.DecodeIDFromRandomKey(key)
|