本文整理汇总了Golang中github.com/PandoCloud/pando-cloud/pkg/models.Device.ProductID方法的典型用法代码示例。如果您正苦于以下问题:Golang Device.ProductID方法的具体用法?Golang Device.ProductID怎么用?Golang Device.ProductID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/PandoCloud/pando-cloud/pkg/models.Device
的用法示例。
在下文中一共展示了Device.ProductID方法的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
}