本文整理汇总了Golang中github.com/PandoCloud/pando-cloud/pkg/models.Product.ProductKey方法的典型用法代码示例。如果您正苦于以下问题:Golang Product.ProductKey方法的具体用法?Golang Product.ProductKey怎么用?Golang Product.ProductKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/PandoCloud/pando-cloud/pkg/models.Product
的用法示例。
在下文中一共展示了Product.ProductKey方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SaveProduct
// SaveProduct will create a product if the ID field is not initialized
// if ID field is initialized, it will update the conresponding product.
func (r *Registry) SaveProduct(product *models.Product, reply *models.Product) error {
db, err := getDB()
if err != nil {
return err
}
err = db.Save(product).Error
if err != nil {
return err
}
key, err := r.keygen.GenRandomKey(int64(product.ID))
if err != nil {
return err
}
product.ProductKey = key
err = db.Save(product).Error
if err != nil {
return err
}
reply.ID = product.ID
reply.ProductName = product.ProductName
reply.ProductDescription = product.ProductDescription
reply.ProductKey = product.ProductKey
reply.ProductConfig = product.ProductConfig
reply.CreatedAt = product.CreatedAt
reply.UpdatedAt = product.UpdatedAt
return nil
}
示例2: SaveProduct
// SaveProduct will create a product if the ID field is not initialized
// if ID field is initialized, it will update the conresponding product.
func (r *Registry) SaveProduct(product *models.Product, reply *models.Product) error {
db, err := getDB()
if err != nil {
return err
}
err = db.Save(product).Error
if err != nil {
return err
}
key, err := r.keygen.GenRandomKey(int64(product.ID))
if err != nil {
return err
}
product.ProductKey = key
err = db.Save(product).Error
if err != nil {
return err
}
reply = product
return nil
}
示例3: setProduct
func setProduct(target *models.Product, src *models.Product) {
target.ID = src.ID
target.ProductName = src.ProductName
target.ProductDescription = src.ProductDescription
target.ProductKey = src.ProductKey
target.ProductConfig = src.ProductConfig
target.CreatedAt = src.CreatedAt
target.UpdatedAt = src.UpdatedAt
}
示例4: SaveProduct
// SaveProduct will create a product if the ID field is not initialized
// if ID field is initialized, it will update the conresponding product.
func (r *Registry) SaveProduct(product *models.Product, reply *models.Product) error {
db, err := getDB()
if err != nil {
return err
}
if product.ID == 0 {
// create product
err = db.Save(product).Error
if err != nil {
return err
}
key, err := r.keygen.GenRandomKey(int64(product.ID))
if err != nil {
return err
}
product.ProductKey = key
}
err = db.Save(product).Error
if err != nil {
return err
}
cache := getCache()
cacheKey := fmt.Sprintf("Product:%v", product.ID)
if _, ok := cache.Get(cacheKey); ok {
cache.Delete(cacheKey)
}
setProduct(reply, product)
return nil
}