當前位置: 首頁>>代碼示例>>Golang>>正文


Golang models.Vendor類代碼示例

本文整理匯總了Golang中github.com/PandoCloud/pando-cloud/pkg/models.Vendor的典型用法代碼示例。如果您正苦於以下問題:Golang Vendor類的具體用法?Golang Vendor怎麽用?Golang Vendor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Vendor類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: addVendor

func addVendor() error {
	args := models.Vendor{}

	reader := bufio.NewReader(os.Stdin)

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

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

	reply := &models.Vendor{}

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

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

	return nil
}
開發者ID:lg0491986,項目名稱:pando-cloud,代碼行數:32,代碼來源:vendor.go

示例2: SaveVendor

// SaveVendor will create a vendor if the ID field is not initialized
// if ID field is initialized, it will update the conresponding vendor.
func (r *Registry) SaveVendor(vendor *models.Vendor, reply *models.Vendor) error {
	db, err := getDB()
	if err != nil {
		return err
	}

	err = db.Save(vendor).Error
	if err != nil {
		return err
	}

	key, err := r.keygen.GenRandomKey(int64(vendor.ID))
	if err != nil {
		return err
	}

	vendor.VendorKey = key

	err = db.Save(vendor).Error
	if err != nil {
		return err
	}

	reply = vendor
	return nil
}
開發者ID:oskycar,項目名稱:pando-cloud,代碼行數:28,代碼來源:registry.go

示例3: SaveVendor

// SaveVendor will create a vendor if the ID field is not initialized
// if ID field is initialized, it will update the conresponding vendor.
func (r *Registry) SaveVendor(vendor *models.Vendor, reply *models.Vendor) error {
	db, err := getDB()
	if err != nil {
		return err
	}

	err = db.Save(vendor).Error
	if err != nil {
		return err
	}

	key, err := r.keygen.GenRandomKey(int64(vendor.ID))
	if err != nil {
		return err
	}

	vendor.VendorKey = key

	err = db.Save(vendor).Error
	if err != nil {
		return err
	}

	reply.ID = vendor.ID
	reply.VendorName = vendor.VendorName
	reply.VendorDescription = vendor.VendorDescription
	reply.VendorKey = vendor.VendorKey
	reply.CreatedAt = vendor.CreatedAt
	reply.UpdatedAt = vendor.UpdatedAt

	return nil
}
開發者ID:zhouhoo,項目名稱:pando-cloud,代碼行數:34,代碼來源:registry.go

示例4: setVendor

func setVendor(target *models.Vendor, src *models.Vendor) {
	target.ID = src.ID
	target.VendorName = src.VendorName
	target.VendorDescription = src.VendorDescription
	target.VendorKey = src.VendorKey
	target.CreatedAt = src.CreatedAt
	target.UpdatedAt = src.UpdatedAt
}
開發者ID:lg0491986,項目名稱:pando-cloud,代碼行數:8,代碼來源:registry.go

示例5: SaveVendor

// SaveVendor will create a vendor if the ID field is not initialized
// if ID field is initialized, it will update the conresponding vendor.
func (r *Registry) SaveVendor(vendor *models.Vendor, reply *models.Vendor) error {
	db, err := getDB()
	if err != nil {
		return err
	}

	if vendor.ID == 0 {
		// if ID field is not initialized, will generate key first
		err = db.Save(vendor).Error
		if err != nil {
			return err
		}

		key, err := r.keygen.GenRandomKey(int64(vendor.ID))
		if err != nil {
			return err
		}

		vendor.VendorKey = key
	}

	err = db.Save(vendor).Error
	if err != nil {
		return err
	}

	cache := getCache()
	cacheKey := fmt.Sprintf("Vendor:%v", vendor.ID)
	if _, ok := cache.Get(cacheKey); ok {
		cache.Delete(cacheKey)
	}

	setVendor(reply, vendor)

	return nil
}
開發者ID:lg0491986,項目名稱:pando-cloud,代碼行數:38,代碼來源:registry.go


注:本文中的github.com/PandoCloud/pando-cloud/pkg/models.Vendor類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。