当前位置: 首页>>代码示例>>Golang>>正文


Golang models.Product类代码示例

本文整理汇总了Golang中github.com/PandoCloud/pando-cloud/pkg/models.Product的典型用法代码示例。如果您正苦于以下问题:Golang Product类的具体用法?Golang Product怎么用?Golang Product使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Product类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
开发者ID:zhouhoo,项目名称:pando-cloud,代码行数:35,代码来源:registry.go

示例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
}
开发者ID:oskycar,项目名称:pando-cloud,代码行数:28,代码来源:registry.go

示例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.VendorID = src.VendorID
	target.CreatedAt = src.CreatedAt
	target.UpdatedAt = src.UpdatedAt
}
开发者ID:PandoCloud,项目名称:pando-cloud,代码行数:10,代码来源:registry.go

示例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
}
开发者ID:lg0491986,项目名称:pando-cloud,代码行数:38,代码来源:registry.go

示例5: addProduct

func addProduct() error {
	args := models.Product{}

	reader := bufio.NewReader(os.Stdin)

	fmt.Printf("vendor ID: ")
	id, err := reader.ReadString('\n')
	if err != nil {
		return err
	}
	vendor := strings.Replace(id, "\n", "", -1)
	vendorid, err := strconv.Atoi(vendor)
	if err != nil {
		return err
	}
	args.VendorID = int32(vendorid)

	fmt.Printf("product name: ")
	name, err := reader.ReadString('\n')
	if err != nil {
		return err
	}
	args.ProductName = strings.Replace(name, "\n", "", -1)

	fmt.Printf("product description: ")
	desc, err := reader.ReadString('\n')
	if err != nil {
		return err
	}
	args.ProductDescription = strings.Replace(desc, "\n", "", -1)

	fmt.Printf("product config json file: ")
	file, err := reader.ReadString('\n')
	if err != nil {
		return err
	}
	jsonfile := strings.Replace(file, "\n", "", -1)
	fi, err := os.Open(jsonfile)
	if err != nil {
		return err
	}
	content, err := ioutil.ReadAll(fi)
	config := string(content)
	fi.Close()
	_, err = productconfig.New(config)
	if err != nil {
		return err
	}
	args.ProductConfig = config

	reply := &models.Product{}

	err = server.RPCCallByName("registry", "Registry.SaveProduct", &args, reply)
	if err != nil {
		return err
	}

	fmt.Println("=======> product created successfully:")
	printStruct(reply)
	fmt.Println("=======")

	return nil
}
开发者ID:lg0491986,项目名称:pando-cloud,代码行数:63,代码来源:product.go


注:本文中的github.com/PandoCloud/pando-cloud/pkg/models.Product类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。