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


Golang model.NewAppError函数代码示例

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


在下文中一共展示了NewAppError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Delete

func (us BoltUserStore) Delete(userId string) StoreChannel {
	storeChannel := make(StoreChannel)

	go func() {
		result := StoreResult{}

		if len(userId) <= 0 {
			result.Err = model.NewAppError("BoltUserStore.Delete", "You must get userId in delete", "user_id = "+userId)
			storeChannel <- result
			close(storeChannel)
		}

		err := us.usersBucket.Delete([]byte(userId))
		if err != nil {
			result.Err = model.NewAppError("BoltUserStore.Delete", err.Error(), "")
			storeChannel <- result
			close(storeChannel)
		}

		result.Data = "ok"

		storeChannel <- result
		close(storeChannel)
	}()

	return storeChannel
}
开发者ID:sichacvah,项目名称:portable_chat,代码行数:27,代码来源:bolt_user_store.go

示例2: GetMember

func (cs BoltChannelStore) GetMember(channelId string, userId string) StoreChannel {
	storeChannel := make(StoreChannel)

	go func() {
		var result StoreResult
		var member *model.ChannelMember
		var itemString string
		notFound := true

		items, err := cs.channelMembersBucket.Items()
		if err != nil {
			result.Err = model.NewAppError("BoltChannelStore.GetMember", "Error while get members", "")
		} else {
			for _, item := range items {
				itemString = string(item.Value)
				member = model.ChannelMemberFromJson(strings.NewReader(itemString))
				if member.ChannelId == channelId && member.UserId == userId {
					result.Data = member
					notFound = false
				}
			}
			if notFound {
				result.Err = model.NewAppError("BoltChannelStore.GetMember", "Not found", "")
			}
		}

		storeChannel <- result
		close(storeChannel)
		return
	}()

	return storeChannel
}
开发者ID:sichacvah,项目名称:portable_chat,代码行数:33,代码来源:bolt_channel_store.go

示例3: DeleteMember

func (cs BoltChannelStore) DeleteMember(member *model.ChannelMember) StoreChannel {
	storeChannel := make(StoreChannel)
	go func() {
		var result StoreResult
		var key string
		var memberJson string
		var m *model.ChannelMember
		items, err := cs.channelMembersBucket.Items()
		if err != nil {
			result.Err = model.NewAppError("BoltChannelStore.SaveMember", "Error while save members", "")
		} else {
			for _, item := range items {
				memberJson = string(item.Value)
				m = model.ChannelMemberFromJson(strings.NewReader(memberJson))
				if member.UserId == m.UserId && member.ChannelId == m.ChannelId {
					key = string(item.Key)
					break
				}
				err := cs.channelMembersBucket.Delete([]byte(key))
				if err != nil {
					result.Err = model.NewAppError("BoltChannelStore.SaveMember", "Error while save members", "")
				} else {
					result.Data = "ok"
				}

			}

		}

		storeChannel <- result
		close(storeChannel)
		return
	}()
	return storeChannel
}
开发者ID:sichacvah,项目名称:portable_chat,代码行数:35,代码来源:bolt_channel_store.go

示例4: GetPosts

func (ps BoltPostStore) GetPosts(channelID string) StoreChannel {
	storeChannel := make(StoreChannel)

	go func() {
		var result StoreResult
		posts := make(map[string]*model.Post)
		channelPostsJson, err := ps.postsByChannel.Get([]byte(channelID))
		if err != nil {
			result.Err = model.NewAppError("BoltPostStore.", "Post is not valid", "")
		} else {
			channelPosts := model.BoolMapFromJson(strings.NewReader(string(channelPostsJson)))
			postItems, err := ps.postStore.Items()
			if err != nil {
				result.Err = model.NewAppError("BoltPostStore.", "Post is not valid", "")
				storeChannel <- result
				close(storeChannel)
				return
			}

			for _, postItem := range postItems {
				if channelPosts[string(postItem.Key)] {
					postString := string(postItem.Value)
					posts[string(postItem.Key)] = model.PostFromJson(strings.NewReader(postString))
				}
			}
			result.Data = posts
		}

		storeChannel <- result
		close(storeChannel)
		return
	}()

	return storeChannel
}
开发者ID:sichacvah,项目名称:portable_chat,代码行数:35,代码来源:bolt_post_store.go

示例5: SaveMember

func (cs BoltChannelStore) SaveMember(member *model.ChannelMember) StoreChannel {
	storeChannel := make(StoreChannel)
	go func() {
		var result StoreResult
		items, err := cs.channelMembersBucket.Items()
		if err != nil {
			result.Err = model.NewAppError("BoltChannelStore.SaveMember", "Error while save members", "")
		} else {
			id := len(items) + 1
			if len(items) <= 0 {
				member.Role = model.CHANNEL_ROLE_ADMIN
			}
			err := cs.channelMembersBucket.Put([]byte(strconv.Itoa(id)), []byte(member.ToJson()))
			if err != nil {
				result.Err = model.NewAppError("BoltChannelStore.SaveMember", "Error while save members", "")
			} else {
				result.Data = member
			}
		}

		storeChannel <- result
		close(storeChannel)
		return
	}()
	return storeChannel
}
开发者ID:sichacvah,项目名称:portable_chat,代码行数:26,代码来源:bolt_channel_store.go

示例6: Update

func (us BoltUserStore) Update(user *model.User) StoreChannel {
	storeChannel := make(StoreChannel)

	go func() {
		result := StoreResult{}

		if len(user.Password) > 0 {
			if user.PasswordConfirmation != user.Password {
				result.Err = model.NewAppError("BoltUserStore.Update", "When update password must be equal to passwordConfirmation", "user_id"+user.Id)
				storeChannel <- result
				close(storeChannel)
			}
		}
		if us.isLoginTaken(user.Login) {
			result.Err = model.NewAppError("BoltUserStore.Save", "User Login already taken", "user_login="+user.Login)
			storeChannel <- result
			close(storeChannel)
			return
		}

		user.PreSave()
		userJson := user.ToJson()
		us.usersBucket.Put([]byte(user.Id), []byte(userJson))
		us.usersByLoginBucket.Put([]byte(user.Login), []byte(user.Id))

		result.Data = user

		storeChannel <- result
		return
	}()

	return storeChannel
}
开发者ID:sichacvah,项目名称:portable_chat,代码行数:33,代码来源:bolt_user_store.go

示例7: SetNewChannelAdmin

func SetNewChannelAdmin(channelId string, userId string, oldAdminId string) error {
	if len(userId) <= 0 || userId == oldAdminId {
		return model.NewAppError("api.SetNewChannelAdmin", "Wrong User id", "")
	}

	om := <-Srv.Store.Channel().GetMember(channelId, oldAdminId)
	if om.Err != nil {
		return om.Err
	}
	oldAdmin := om.Data.(*model.ChannelMember)
	oldAdmin.Role = model.CHANNEL_ROLE_USER

	nm := <-Srv.Store.Channel().GetMember(channelId, userId)
	if nm.Err != nil {
		return nm.Err
	}

	newAdmin := nm.Data.(*model.ChannelMember)
	newAdmin.Role = model.CHANNEL_ROLE_ADMIN

	result1 := <-Srv.Store.Channel().SaveMember(oldAdmin)
	if result1.Err != nil {
		return result1.Err
	}

	result2 := <-Srv.Store.Channel().SaveMember(newAdmin)
	if result2.Err != nil {
		return result2.Err
	}

	return nil
}
开发者ID:sichacvah,项目名称:portable_chat,代码行数:32,代码来源:channel.go

示例8: GetUsers

func (us BoltUserStore) GetUsers() StoreChannel {
	storeChannel := make(StoreChannel)

	go func() {
		var userString string
		var user *model.User
		users := []string{}

		result := StoreResult{}

		items, err := us.usersBucket.Items()

		if err != nil {
			result.Err = model.NewAppError("BoltUserStore.GetUsers", err.Error(), "")
			storeChannel <- result
			close(storeChannel)
		}

		for _, item := range items {
			userString = string(item.Value)
			user = model.UserFromJson(strings.NewReader(userString))
			user.Sanitize()
			users = append(users, string(user.ToJson()))
		}

		result.Data = users
		storeChannel <- result
		close(storeChannel)
	}()

	return storeChannel
}
开发者ID:sichacvah,项目名称:portable_chat,代码行数:32,代码来源:bolt_user_store.go

示例9: Update

func (ps BoltPostStore) Update(post *model.Post) StoreChannel {
	storeChannel := make(StoreChannel)

	go func() {
		var result StoreResult
		postErr := post.IsValid()
		if postErr != nil {
			err := ps.postStore.Put([]byte(post.Id), []byte(post.ToJson()))

			if err != nil {
				result.Err = model.NewAppError("BoltPostStore.", "Post is not valid", "")
			} else {
				result.Data = post
			}
		} else {
			result.Err = postErr
		}

		storeChannel <- result
		close(storeChannel)
		return
	}()

	return storeChannel
}
开发者ID:sichacvah,项目名称:portable_chat,代码行数:25,代码来源:bolt_post_store.go

示例10: GetMembers

func (cs BoltChannelStore) GetMembers(channel *model.Channel) StoreChannel {
	storeChannel := make(StoreChannel)

	go func() {
		var result StoreResult

		items, err := cs.channelMembersBucket.Items()
		if err != nil {
			result.Err = model.NewAppError("BoltChannelStore.GetMembers", "Error while get members", "")
		} else {
			resultData := make(map[*model.ChannelMember]bool)
			for _, item := range items {
				memberJson := string(item.Value)
				member := model.ChannelMemberFromJson(strings.NewReader(memberJson))
				if member.ChannelId == channel.Id {
					resultData[member] = true
				}
			}

			result.Data = resultData
		}

		storeChannel <- result
		close(storeChannel)
		return
	}()

	return storeChannel
}
开发者ID:sichacvah,项目名称:portable_chat,代码行数:29,代码来源:bolt_channel_store.go

示例11: GetChannels

func (cs BoltChannelStore) GetChannels(userId string) StoreChannel {
	storeChannel := make(StoreChannel)

	go func() {
		var result StoreResult
		var channel *model.Channel

		items, err := cs.channelsBucket.Items()
		if err != nil || len(userId) <= 0 {
			result.Err = model.NewAppError("BoltChannelStore.GetChannels", "Error while get items", "")
		} else {
			data := make(map[*model.Channel]bool)

			for _, item := range items {
				channel = model.ChannelFromJson(strings.NewReader(string(item.Value)))
				if channel != nil {
					data[channel] = true
				}
			}
			result.Data = data
		}

		storeChannel <- result
		close(storeChannel)
		return
	}()

	return storeChannel
}
开发者ID:sichacvah,项目名称:portable_chat,代码行数:29,代码来源:bolt_channel_store.go

示例12: Save

func (ps BoltPostStore) Save(post *model.Post) StoreChannel {
	storeChannel := make(StoreChannel)

	go func() {
		var result StoreResult
		postErr := post.IsValid()
		if postErr != nil {
			post.PreSave()
			err := ps.postStore.Put([]byte(post.Id), []byte(post.ToJson()))

			postsByChannelsJson, err := ps.postsByChannel.Get([]byte(post.ChannelId))
			postsByChannelsString := string(postsByChannelsJson)
			postsByChannels := model.BoolMapFromJson(strings.NewReader(postsByChannelsString))
			postsByChannels[post.Id] = true

			postsByChannelsString = model.BoolMapToJson(postsByChannels)

			err = ps.postStore.Put([]byte(post.ChannelId), []byte(postsByChannelsString))

			if err != nil {
				result.Err = model.NewAppError("BoltPostStore.", "Post is valid", "")
			} else {
				result.Data = post
			}
		} else {
			result.Err = postErr
		}

		storeChannel <- result
		close(storeChannel)
		return
	}()

	return storeChannel
}
开发者ID:sichacvah,项目名称:portable_chat,代码行数:35,代码来源:bolt_post_store.go

示例13: GetChannelMembers

func (cs BoltChannelStore) GetChannelMembers(channelId string) StoreChannel {
	storeChannel := make(StoreChannel)

	go func() {
		var result StoreResult
		var channelMember *model.ChannelMember
		items, err := cs.channelsBucket.Items()

		if err != nil {
			result.Err = model.NewAppError("BoltChannelStore.GetChannelMembers", "Error while get members", "")
		} else {
			data := make(map[*model.ChannelMember]bool)
			for _, item := range items {
				itemString := string(item.Value)
				channelMember = model.ChannelMemberFromJson(strings.NewReader(itemString))
				if channelMember != nil && channelId == channelMember.ChannelId {
					data[channelMember] = true
				}
			}
			result.Data = data
		}
		storeChannel <- result
		close(storeChannel)
		return
	}()

	return storeChannel
}
开发者ID:sichacvah,项目名称:portable_chat,代码行数:28,代码来源:bolt_channel_store.go

示例14: GetByName

func (cs BoltChannelStore) GetByName(name string) StoreChannel {
	storeChannel := make(StoreChannel)

	go func() {
		var result StoreResult

		items, err := cs.channelsBucket.Items()
		if err != nil {
			result.Err = model.NewAppError("BoltChannelStore.GetByName", "Error while get by name", "")
			storeChannel <- result
			close(storeChannel)
			return
		}

		for _, item := range items {
			channel := model.ChannelFromJson(strings.NewReader(string(item.Value)))
			if channel.Name == name {
				result.Data = channel
				storeChannel <- result
				close(storeChannel)
				return
			}
		}
	}()

	return storeChannel
}
开发者ID:sichacvah,项目名称:portable_chat,代码行数:27,代码来源:bolt_channel_store.go

示例15: GetPost

func GetPost(postId string) (*model.Post, *model.AppError) {
	result := <-Srv.Store.Post().Get(postId)
	if result.Err != nil {
		return nil, result.Err
	}

	if result.Data.(*model.Post) == nil {
		return nil, model.NewAppError("Get Post", "Post not found", "")
	}

	return result.Data.(*model.Post), nil
}
开发者ID:sichacvah,项目名称:portable_chat,代码行数:12,代码来源:post.go


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