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


Golang utils.PrintStackAndError函數代碼示例

本文整理匯總了Golang中github.com/kobeld/duoerl/utils.PrintStackAndError函數的典型用法代碼示例。如果您正苦於以下問題:Golang PrintStackAndError函數的具體用法?Golang PrintStackAndError怎麽用?Golang PrintStackAndError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: CreatePost

func CreatePost(input *duoerlapi.PostInput) (originInput *duoerlapi.PostInput, err error) {
	originInput = input

	// simple validation
	if input.Content == "" {
		err = global.CanNotBeBlankError
		return
	}

	postId, err := utils.ToObjectId(input.Id)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	authorId, err := utils.ToObjectId(input.AuthorId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	post := &posts.Post{
		Id:       postId,
		Content:  input.Content,
		AuthorId: authorId,
	}

	if err = post.Save(); err != nil {
		utils.PrintStackAndError(err)
		return
	}

	return
}
開發者ID:kobeld,項目名稱:duoerl,代碼行數:34,代碼來源:post_services.go

示例2: CreateBrand

func CreateBrand(brandInput *duoerlapi.BrandInput) (input *duoerlapi.BrandInput, err error) {
	input = brandInput

	oId, err := utils.ToObjectId(brandInput.Id)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	brand := &brands.Brand{
		Id:      oId,
		Name:    brandInput.Name,
		Alias:   brandInput.Alias,
		Intro:   brandInput.Intro,
		Country: brandInput.Country,
		Website: brandInput.Website,
		Logo:    brandInput.Logo,
	}

	if err = brand.Save(); err != nil {
		utils.PrintStackAndError(err)
		return
	}

	return
}
開發者ID:kobeld,項目名稱:duoerl,代碼行數:26,代碼來源:brand_services.go

示例3: CreateFollowBrand

func CreateFollowBrand(userId, brandId string) (err error) {

	userOId, err := utils.ToObjectId(userId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	brandOId, err := utils.ToObjectId(brandId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	// Validation, check if the record has been created
	followBrand, err := followbrands.FindByUserAndBrandId(userOId, brandOId)
	if followBrand != nil {
		return
	}

	followBrand = &followbrands.FollowBrand{
		UserId:  userOId,
		BrandId: brandOId,
	}

	if err = followBrand.Save(); err != nil {
		utils.PrintStackAndError(err)
		return
	}

	return
}
開發者ID:kobeld,項目名稱:duoerl,代碼行數:32,代碼來源:followbrand_services.go

示例4: AllProducts

func AllProducts() (apiProducts []*duoerlapi.Product, err error) {

	// Find all the products
	dbProducts, err := products.FindAll(bson.M{})
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	// Collect brand/author Ids and find them
	brandIds, authorIds := products.CollectBrandAndAuthorIds(dbProducts)

	dbBrands, err := brands.FindByIds(brandIds)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	dbAuthors, err := users.FindByIds(authorIds)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	// Build the brandMap and authorMap
	brandMap := brands.BuildBrandMap(dbBrands)
	authorMap := users.BuildUserMap(dbAuthors)

	apiProducts = toApiProducts(dbProducts, brandMap, authorMap)

	return
}
開發者ID:kobeld,項目名稱:duoerl,代碼行數:32,代碼來源:product_services.go

示例5: CreateNote

func CreateNote(input *duoerlapi.NoteInput) (originInput *duoerlapi.NoteInput, err error) {
	originInput = input

	noteId, err := utils.ToObjectId(input.Id)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	authorId, err := utils.ToObjectId(input.AuthorId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	note := &notes.Note{
		Id:      noteId,
		Article: *articles.NewArticle(input.Title, input.Content, authorId),
	}

	if err = note.Save(); err != nil {
		utils.PrintStackAndError(err)
		return
	}

	return
}
開發者ID:kobeld,項目名稱:duoerl,代碼行數:27,代碼來源:note_services.go

示例6: ShowBrand

func ShowBrand(brandId, userId string) (apiBrand *duoerlapi.Brand, err error) {
	brandOId, err := utils.ToObjectId(brandId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	brand, err := brands.FindById(brandOId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	apiBrand = toApiBrand(brand)
	apiBrand.BrandStats = getBrandStats(brandOId)

	// Not login user
	if userId == "" {
		return
	}

	if followBrand := GetFollowBrand(userId, brandId); followBrand != nil {
		apiBrand.HasFollowed = true
	}

	return
}
開發者ID:kobeld,項目名稱:duoerl,代碼行數:27,代碼來源:brand_services.go

示例7: AddWishItem

func AddWishItem(userId, productId string) (err error) {

	userOId, err := utils.ToObjectId(userId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	productOId, err := utils.ToObjectId(productId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	// Validation, check if the record has been created
	wishItem, err := wishitems.FindByUserAndProductId(userOId, productOId)
	if wishItem != nil {
		return
	}

	wishItem = &wishitems.WishItem{
		UserId:    userOId,
		ProductId: productOId,
	}

	if err = wishItem.Save(); err != nil {
		utils.PrintStackAndError(err)
		return
	}

	return
}
開發者ID:kobeld,項目名稱:duoerl,代碼行數:32,代碼來源:wish_item_services.go

示例8: AddOwnItem

func AddOwnItem(ownItemInput *duoerlapi.OwnItemInput) (err error) {

	userOId, err := utils.ToObjectId(ownItemInput.UserId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	productOId, err := utils.ToObjectId(ownItemInput.ProductId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	// Validation, check if the record has been created
	ownItem, err := ownitems.FindByUserAndProductId(userOId, productOId)
	if ownItem != nil {
		return
	}

	ownItem = &ownitems.OwnItem{
		UserId:    userOId,
		ProductId: productOId,
		GotFrom:   ownItemInput.GotFrom,
	}

	if err = ownItem.Save(); err != nil {
		utils.PrintStackAndError(err)
		return
	}

	return
}
開發者ID:kobeld,項目名稱:duoerl,代碼行數:33,代碼來源:own_item_services.go

示例9: UpdateBrand

func UpdateBrand(input *duoerlapi.BrandInput) (originInput *duoerlapi.BrandInput, err error) {
	originInput = input

	brandOId, err := utils.ToObjectId(input.Id)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	brand, err := brands.FindById(brandOId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	brand.Name = input.Name
	brand.Alias = input.Alias
	brand.Intro = input.Intro
	brand.Country = input.Country
	brand.Logo = input.Logo
	brand.Website = input.Website

	if err = brand.Save(); err != nil {
		utils.PrintStackAndError(err)
		return
	}

	return
}
開發者ID:kobeld,項目名稱:duoerl,代碼行數:29,代碼來源:brand_services.go

示例10: populateCachedCategoriesRelated

func populateCachedCategoriesRelated() {

	apiCategoryMap := make(map[string]*duoerlapi.Category)
	apiSubCategoryMap := make(map[string]*duoerlapi.SubCategory)
	apiEfficacyMap := make(map[string]*duoerlapi.Efficacy)

	apiCategories := []*duoerlapi.Category{}
	apiSubCategories := []*duoerlapi.SubCategory{}

	// Get all Categories
	allCategories, err := categories.FindAll(nil)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	for _, category := range allCategories {
		switch category.Level {
		case categories.LEVEL_ONE:
			apiCategory := toApiCategory(category)
			apiCategoryMap[apiCategory.Id] = apiCategory
			apiCategories = append(apiCategories, apiCategory)

		case categories.LEVEL_TWO:
			apiSubCategory := toApiSubCategory(category)
			apiSubCategories = append(apiSubCategories, apiSubCategory)
			apiSubCategoryMap[apiSubCategory.Id] = apiSubCategory
		}
	}

	for _, apiSubCategory := range apiSubCategories {
		if apiCategory, exist := apiCategoryMap[apiSubCategory.ParentId]; exist {
			apiCategory.SubCategories = append(apiCategory.SubCategories, apiSubCategory)
		}
	}

	// Get all Efficacies
	allEfficacies, err := efficacies.FindAll(nil)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	for _, efficacy := range allEfficacies {
		apiEfficacy := toApiEfficacy(efficacy)
		apiEfficacyMap[apiEfficacy.Id] = apiEfficacy
		if apiCategory, exist := apiCategoryMap[apiEfficacy.ParentId]; exist {
			apiCategory.Efficacies = append(apiCategory.Efficacies, apiEfficacy)
		}
	}

	global.Categories = apiCategories
	global.CategoryMap = apiCategoryMap
	global.SubCategoryMap = apiSubCategoryMap
	global.EfficacyMap = apiEfficacyMap

	return
}
開發者ID:kobeld,項目名稱:duoerl,代碼行數:58,代碼來源:cache_services.go

示例11: FetchByIdHex

func FetchByIdHex(idHex string) (user *User, err error) {
	userId, err := utils.ToObjectId(idHex)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	user, err = FindById(userId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	return
}
開發者ID:kobeld,項目名稱:duoerl,代碼行數:15,代碼來源:user_curd.go

示例12: GetFollowBrand

func GetFollowBrand(userId, brandId string) (followBrand *followbrands.FollowBrand) {
	userOId, err := utils.ToObjectId(userId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	brandOId, err := utils.ToObjectId(brandId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	followBrand, _ = followbrands.FindByUserAndBrandId(userOId, brandOId)

	return
}
開發者ID:kobeld,項目名稱:duoerl,代碼行數:17,代碼來源:followbrand_services.go

示例13: GetBrandFollowers

func GetBrandFollowers(brandIdHex string) (apiUsers []*duoerlapi.User, err error) {

	brandId, err := utils.ToObjectId(brandIdHex)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	followbrandz, err := followbrands.FindByBrandId(brandId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	maxNum := len(followbrandz)
	// Get random number users
	if maxNum > configs.BRAND_SHOW_FOLLOWER_NUM {
		randIndex, err := randutil.IntRange(0, maxNum)
		if err != nil {
			utils.PrintStackAndError(err)
			randIndex = 0
		}

		leftIndex := randIndex - configs.BRAND_SHOW_FOLLOWER_NUM
		if leftIndex < 0 {
			followbrandz = followbrandz[0:configs.BRAND_SHOW_FOLLOWER_NUM]
		} else {
			followbrandz = followbrandz[leftIndex:randIndex]
		}
	}

	followerIds := []bson.ObjectId{}
	for _, followBrand := range followbrandz {
		followerIds = append(followerIds, followBrand.UserId)
	}

	followers, err := users.FindByIds(followerIds)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	apiUsers = toApiUsers(followers)

	return
}
開發者ID:kobeld,項目名稱:duoerl,代碼行數:46,代碼來源:followbrand_services.go

示例14: CreateReview

// Todo: Validation Needed
func CreateReview(input *duoerlapi.ReviewInput) (originInput *duoerlapi.ReviewInput, err error) {
	originInput = input

	oId, err := utils.ToObjectId(input.Id)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	productOId, err := utils.ToObjectId(input.ProductId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	// Check if the product exists
	product, err := products.FindById(productOId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	authorOId, err := utils.ToObjectId(input.AuthorId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	review := &reviews.Review{
		Id:          oId,
		AuthorId:    authorOId,
		ProductId:   productOId,
		BrandId:     product.BrandId,
		Content:     input.Content,
		Rating:      input.Rating,
		EfficacyIds: utils.TurnPlainIdsToObjectIds(input.EfficacyIds),
	}

	if err = review.Save(); err != nil {
		utils.PrintStackAndError(err)
		return
	}

	return
}
開發者ID:kobeld,項目名稱:duoerl,代碼行數:46,代碼來源:review_services.go

示例15: EditProduct

// For edit product form
func EditProduct(productId string) (productInput *duoerlapi.ProductInput, err error) {

	productOId, err := utils.ToObjectId(productId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	product, err := products.FindById(productOId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	productInput = toProductInput(product)

	return
}
開發者ID:kobeld,項目名稱:duoerl,代碼行數:19,代碼來源:product_services.go


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