| 
														
															@@ -69,7 +69,7 @@ func setDevice(target *models.Device, src *models.Device) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	target.ID = src.ID 
														 | 
														
														 | 
														
															 	target.ID = src.ID 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	target.ProductID = src.ProductID 
														 | 
														
														 | 
														
															 	target.ProductID = src.ProductID 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	target.DeviceIdentifier = src.DeviceIdentifier 
														 | 
														
														 | 
														
															 	target.DeviceIdentifier = src.DeviceIdentifier 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-	target.DeviceSecret = src.DeviceIdentifier 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	target.DeviceSecret = src.DeviceSecret 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	target.DeviceKey = src.DeviceKey 
														 | 
														
														 | 
														
															 	target.DeviceKey = src.DeviceKey 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	target.DeviceName = src.DeviceName 
														 | 
														
														 | 
														
															 	target.DeviceName = src.DeviceName 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	target.DeviceDescription = src.DeviceDescription 
														 | 
														
														 | 
														
															 	target.DeviceDescription = src.DeviceDescription 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -381,13 +381,23 @@ func (r *Registry) FindDeviceById(args uint64, reply *models.Device) error { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	if err != nil { 
														 | 
														
														 | 
														
															 	if err != nil { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		return err 
														 | 
														
														 | 
														
															 		return err 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	} 
														 | 
														
														 | 
														
															 	} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-	d := &models.Device{} 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-	d.ID = uint(args) 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-	err = db.Where(d).First(reply).Error 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-	if err != nil { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-		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) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	} 
														 | 
														
														 | 
														
															 	} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	return nil 
														 | 
														
														 | 
														
															 	return nil 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 } 
														 | 
														
														 | 
														
															 } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -399,7 +409,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 { 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -414,9 +424,12 @@ 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) 
														 |