本文整理匯總了Golang中github.com/PandoCloud/pando-cloud/pkg/models.Device.DeviceVersion方法的典型用法代碼示例。如果您正苦於以下問題:Golang Device.DeviceVersion方法的具體用法?Golang Device.DeviceVersion怎麽用?Golang Device.DeviceVersion使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/PandoCloud/pando-cloud/pkg/models.Device
的用法示例。
在下文中一共展示了Device.DeviceVersion方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RegisterDevice
// RegisterDevice try to register a device to our platform.
// if the device has already been registered,
// the registration will success return the registered device before.
func (r *Registry) RegisterDevice(args *rpcs.ArgsDeviceRegister, reply *models.Device) error {
db, err := getDB()
if err != nil {
return err
}
product := &models.Product{}
err = r.ValidateProduct(args.ProductKey, product)
if err != nil {
return err
}
identifier := genDeviceIdentifier(product.VendorID, product.ID, args.DeviceCode)
if db.Where(&models.Device{DeviceIdentifier: identifier}).First(reply).RecordNotFound() {
// device is not registered yet.
reply.ProductID = product.ID
reply.DeviceIdentifier = identifier
reply.DeviceName = product.ProductName // product name as default device name.
reply.DeviceDescription = product.ProductDescription
reply.DeviceVersion = args.DeviceVersion
err = db.Save(reply).Error
if err != nil {
return err
}
// generate a random device key with hex encoding.
reply.DeviceKey, err = r.keygen.GenRandomKey(reply.ID)
if err != nil {
return err
}
// generate a random password with base64 encoding.
reply.DeviceSecret, err = generator.GenRandomPassword()
if err != nil {
return err
}
err = db.Save(reply).Error
if err != nil {
return err
}
} else {
//delete cache
cache := getCache()
cacheKey := fmt.Sprintf("Device:%v", identifier)
if _, ok := cache.Get(cacheKey); ok {
cache.Delete(cacheKey)
}
// device has aleady been saved. just update version info.
reply.DeviceVersion = args.DeviceVersion
err = db.Save(reply).Error
if err != nil {
return err
}
}
return nil
}
示例2: setDevice
func setDevice(target *models.Device, src *models.Device) {
target.ID = src.ID
target.ProductID = src.ProductID
target.DeviceIdentifier = src.DeviceIdentifier
target.DeviceSecret = src.DeviceIdentifier
target.DeviceKey = src.DeviceKey
target.DeviceName = src.DeviceName
target.DeviceDescription = src.DeviceDescription
target.DeviceVersion = src.DeviceVersion
target.CreatedAt = src.CreatedAt
target.UpdatedAt = src.UpdatedAt
}