• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang store.Tat函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: changeUsernameOnPrivateTopics

func changeUsernameOnPrivateTopics(oldUsername, newUsername string) error {
	var topics []tat.Topic

	err := store.Tat().CTopics.Find(
		bson.M{
			"topic": bson.RegEx{
				Pattern: "^/Private/" + oldUsername + ".*$", Options: "i",
			}}).All(&topics)

	if err != nil {
		log.Errorf("Error while getting topic with username %s for rename to %s on Topics %s", oldUsername, newUsername, err)
	}

	for _, topic := range topics {
		newTopicName := strings.Replace(topic.Topic, oldUsername, newUsername, 1)
		errUpdate := store.Tat().CTopics.Update(
			bson.M{"_id": topic.ID},
			bson.M{"$set": bson.M{"topic": newTopicName}},
		)
		if errUpdate != nil {
			log.Errorf("Error while update Topic name from %s to %s :%s", topic.Topic, newTopicName, errUpdate)
		}
	}

	return err
}
开发者ID:ovh,项目名称:tat,代码行数:26,代码来源:topic.go


示例2: actionOnSetParameter

func actionOnSetParameter(topic *tat.Topic, operand, set, admin string, newParam tat.TopicParameter, recursive bool, history string) error {

	var selector bson.M

	if recursive {
		selector = bson.M{"topic": bson.RegEx{Pattern: "^" + topic.Topic + ".*$"}}
	} else {
		selector = bson.M{"_id": topic.ID}
	}

	var err error
	if operand == "$pull" {
		_, err = store.Tat().CTopics.UpdateAll(
			selector,
			bson.M{operand: bson.M{set: bson.M{"key": newParam.Key}}},
		)
	} else {
		_, err = store.Tat().CTopics.UpdateAll(
			selector,
			bson.M{operand: bson.M{set: bson.M{"key": newParam.Key, "value": newParam.Value}}},
		)
	}

	if err != nil {
		return err
	}
	return addToHistory(topic, selector, admin, history+" "+newParam.Key+":"+newParam.Value)
}
开发者ID:ovh,项目名称:tat,代码行数:28,代码来源:topic.go


示例3: FindAllTopicsWithCollections

// FindAllTopicsWithCollections returns the total number of topics in db
func FindAllTopicsWithCollections() ([]tat.Topic, error) {
	var topics []tat.Topic
	err := store.Tat().CTopics.Find(bson.M{"collection": bson.M{"$exists": true, "$ne": ""}}).
		Select(bson.M{"_id": 1, "collection": 1, "topic": 1}).
		All(&topics)
	return topics, err
}
开发者ID:ovh,项目名称:tat,代码行数:8,代码来源:topic.go


示例4: listTopicsCursor

func listTopicsCursor(criteria *tat.TopicCriteria, user *tat.User) (*mgo.Query, error) {
	c, err := buildTopicCriteria(criteria, user)
	if err != nil {
		return nil, err
	}
	return store.Tat().CTopics.Find(c), nil
}
开发者ID:ovh,项目名称:tat,代码行数:7,代码来源:topic.go


示例5: Insert

// Insert a new user, return tokenVerify to user, in order to
// validate account after check email
func Insert(user *tat.User) (string, error) {
	user.ID = bson.NewObjectId().Hex()

	user.DateCreation = time.Now().Unix()
	user.Auth.DateAskReset = time.Now().Unix()
	user.Auth.EmailVerified = false
	user.IsSystem = false
	user.IsArchived = false
	user.CanWriteNotifications = false
	user.CanListUsersAsAdmin = false
	nbUsers, err := CountUsers()
	if err != nil {
		log.Errorf("Error while count all users%s", err)
		return "", err
	}
	if nbUsers > 0 {
		user.IsAdmin = false
	} else {
		log.Infof("user %s is the first user, he is now admin", user.Username)
		user.IsAdmin = true
	}
	tokenVerify := ""
	tokenVerify, user.Auth.HashedTokenVerify, err = generateUserPassword()
	if err != nil {
		log.Errorf("Error while generate Token Verify for new user %s", err)
		return tokenVerify, err
	}

	if err = store.Tat().CUsers.Insert(user); err != nil {
		log.Errorf("Error while inserting new user %s", err)
	}
	return tokenVerify, err
}
开发者ID:ovh,项目名称:tat,代码行数:35,代码来源:user.go


示例6: addToHistory

func addToHistory(group *tat.Group, user string, historyToAdd string) error {
	toAdd := strconv.FormatInt(time.Now().Unix(), 10) + " " + user + " " + historyToAdd
	return store.Tat().CGroups.Update(
		bson.M{"_id": group.ID},
		bson.M{"$addToSet": bson.M{"history": toAdd}},
	)
}
开发者ID:ovh,项目名称:tat,代码行数:7,代码来源:group.go


示例7: findByUsernameAndTokenVerify

// FindByUsernameAndPassword search username, use user's salt to generates tokenVerify
// and check username + hashedTokenVerify in DB
func findByUsernameAndTokenVerify(user *tat.User, username, tokenVerify string) (bool, error) {
	var tmpUser = tat.User{}
	err := store.Tat().CUsers.
		Find(bson.M{"username": username}).
		Select(bson.M{"auth.emailVerify": 1, "auth.hashedTokenVerify": 1, "auth.saltTokenVerify": 1, "auth.dateAskReset": 1}).
		One(&tmpUser)
	if err != nil {
		return false, fmt.Errorf("findByUsernameAndTokenVerify > Error while fetching hashed Token Verify with username %s", username)
	}

	// dateAskReset more than 30 min, expire token
	if time.Since(time.Unix(tmpUser.Auth.DateAskReset, 0)).Minutes() > 30 {
		return false, fmt.Errorf("Token Validation expired. Please ask a reset of your password with username %s", username)
	}
	if !isCheckValid(tokenVerify, tmpUser.Auth.HashedTokenVerify) {
		return false, fmt.Errorf("Error while checking user %s with given token", username)
	}

	// ok, user is checked, get all fields now
	found, err := FindByUsername(user, username)
	if !found || err != nil {
		return false, err
	}

	return tmpUser.Auth.EmailVerified, nil
}
开发者ID:ovh,项目名称:tat,代码行数:28,代码来源:user.go


示例8: AllTopicsSetParam

// AllTopicsSetParam computes Tags on all topics
func AllTopicsSetParam(key, value string) (string, error) {
	var topics []tat.Topic
	err := store.Tat().CTopics.Find(bson.M{}).
		Select(GetTopicSelectedFields(true, false, false, false)).
		All(&topics)

	if err != nil {
		log.Errorf("Error while getting all topics for set a param")
		return "", err
	}

	errTxt := ""
	nOk := 1
	for _, topic := range topics {
		if err := setAParam(&topic, key, value); err != nil {
			log.Errorf("Error while set param %s on topic %s: %s", key, topic.Topic, err.Error())
			errTxt += fmt.Sprintf(" Error set param %s on topic %s", key, topic.Topic)
		} else {
			log.Infof(" %s param setted on topic %s", key, topic.Topic)
			nOk++
		}
	}

	if errTxt != "" {
		return "", fmt.Errorf(errTxt)
	}

	return fmt.Sprintf("Param setted on %d topics", nOk), nil
}
开发者ID:ovh,项目名称:tat,代码行数:30,代码来源:topic.go


示例9: AskReset

// AskReset generate a new saltTokenVerify / hashedTokenVerify
// return tokenVerify (to be sent to user by mail)
func AskReset(user *tat.User) (string, error) {

	err := FindByUsernameAndEmail(user, user.Username, user.Email)
	if err != nil {
		return "", err
	}

	tokenVerify, hashedTokenVerify, err := generateUserPassword()
	if err != nil {
		log.Errorf("Error while generate Token for reset password %s", err)
		return tokenVerify, err
	}

	err = store.Tat().CUsers.Update(
		bson.M{"_id": user.ID},
		bson.M{"$set": bson.M{
			"auth.hashedTokenVerify": hashedTokenVerify,
			"auth.dateAskReset":      time.Now().Unix(),
		}})

	if err != nil {
		log.Errorf("Error while ask reset user %s", err)
	}
	return tokenVerify, err
}
开发者ID:ovh,项目名称:tat,代码行数:27,代码来源:user.go


示例10: listUsersCursor

func listUsersCursor(criteria *tat.UserCriteria, isAdmin bool) (*mgo.Query, error) {
	c, err := buildUserCriteria(criteria)
	if err != nil {
		return nil, err
	}
	return store.Tat().CUsers.Find(c), nil
}
开发者ID:ovh,项目名称:tat,代码行数:7,代码来源:user.go


示例11: listGroupsCursor

func listGroupsCursor(criteria *tat.GroupCriteria, user *tat.User) (*mgo.Query, error) {
	c, err := buildGroupCriteria(criteria, user)
	if err != nil {
		return nil, err
	}
	return store.Tat().CGroups.Find(c), nil
}
开发者ID:ovh,项目名称:tat,代码行数:7,代码来源:group.go


示例12: AllTopicsComputeTags

// AllTopicsComputeTags computes Tags on all topics
func AllTopicsComputeTags() (string, error) {
	var topics []tat.Topic
	err := store.Tat().CTopics.Find(bson.M{}).
		Select(GetTopicSelectedFields(true, false, false, false)).
		All(&topics)

	if err != nil {
		log.Errorf("Error while getting all topics for compute tags")
		return "", err
	}

	errTxt := ""
	infoTxt := ""
	for _, topic := range topics {
		if topic.IsAutoComputeTags {
			n, err := ComputeTags(&topic)
			if err != nil {
				log.Errorf("Error while compute tags on topic %s: %s", topic.Topic, err.Error())
				errTxt += fmt.Sprintf(" Error compute tags on topic %s", topic.Topic)
			} else {
				infoTxt += fmt.Sprintf(" %d tags computed on topic %s", n, topic.Topic)
				log.Infof(infoTxt)
			}
		}
	}

	if errTxt != "" {
		return infoTxt, fmt.Errorf(errTxt)
	}
	return infoTxt, nil
}
开发者ID:ovh,项目名称:tat,代码行数:32,代码来源:topic.go


示例13: UpdateTopicLabels

// UpdateTopicLabels updates labels on topic
func UpdateTopicLabels(topic *tat.Topic, labels []tat.Label) {
	if !topic.IsAutoComputeLabels || len(labels) == 0 {
		return
	}

	update := false
	newLabels := topic.Labels
	for _, label := range labels {
		find := false
		for _, tlabel := range topic.Labels {
			if label.Text == tlabel.Text {
				find = true
				continue
			}
		}
		if !find {
			newLabels = append(newLabels, label)
			update = true
		}
	}

	if update {
		err := store.Tat().CTopics.Update(
			bson.M{"_id": topic.ID},
			bson.M{"$set": bson.M{"labels": newLabels}})

		if err != nil {
			log.Errorf("UpdateTopicLabels> Error while updating labels on topic")
		} else {
			log.Debugf("UpdateTopicLabels> Topic %s ", topic.Topic)
		}
		cache.CleanTopicByName(topic.Topic)
	}
}
开发者ID:ovh,项目名称:tat,代码行数:35,代码来源:topic.go


示例14: UpdateTopicTags

// UpdateTopicTags updates tags on topic
func UpdateTopicTags(topic *tat.Topic, tags []string) {
	if !topic.IsAutoComputeTags || len(tags) == 0 {
		return
	}

	update := false
	newTags := topic.Tags
	for _, tag := range tags {
		if !tat.ArrayContains(topic.Tags, tag) {
			update = true
			newTags = append(newTags, tag)
		}
	}

	if update {
		err := store.Tat().CTopics.Update(
			bson.M{"_id": topic.ID},
			bson.M{"$set": bson.M{"tags": newTags}})

		if err != nil {
			log.Errorf("UpdateTopicTags> Error while updating tags on topic")
		} else {
			log.Debugf("UpdateTopicTags> Topic %s ", topic.Topic)
		}
		cache.CleanTopicByName(topic.Topic)
	}
}
开发者ID:ovh,项目名称:tat,代码行数:28,代码来源:topic.go


示例15: listPresencesCursor

func listPresencesCursor(criteria *tat.PresenceCriteria, allFields bool) (*mgo.Query, error) {
	c, err := buildPresenceCriteria(criteria)
	if err != nil {
		return nil, err
	}
	return store.Tat().CPresences.Find(c), nil
}
开发者ID:ovh,项目名称:tat,代码行数:7,代码来源:presence.go


示例16: addToHistory

func addToHistory(topic *tat.Topic, selector bson.M, user string, historyToAdd string) error {
	toAdd := strconv.FormatInt(time.Now().Unix(), 10) + " " + user + " " + historyToAdd
	_, err := store.Tat().CTopics.UpdateAll(
		selector,
		bson.M{"$addToSet": bson.M{"history": toAdd}},
	)
	return err
}
开发者ID:ovh,项目名称:tat,代码行数:8,代码来源:topic.go


示例17: RemoveFilter

// RemoveFilter add a user filter to the topic
func RemoveFilter(topic *tat.Topic, filter *tat.Filter) error {
	err := store.Tat().CTopics.Update(
		bson.M{"_id": topic.ID},
		bson.M{"$pull": bson.M{"filters": bson.M{"_id": filter.ID}}},
	)
	cache.CleanTopicByName(topic.Topic)
	return err
}
开发者ID:ovh,项目名称:tat,代码行数:9,代码来源:topic.go


示例18: UpdateFilter

// UpdateFilter add a user filter to the topic
func UpdateFilter(topic *tat.Topic, filter *tat.Filter) error {
	err := store.Tat().CTopics.Update(
		bson.M{"_id": topic.ID, "filters._id": filter.ID},
		bson.M{"$set": bson.M{"filters.$": filter}},
	)
	cache.CleanTopicByName(topic.Topic)
	return err
}
开发者ID:ovh,项目名称:tat,代码行数:9,代码来源:topic.go


示例19: TruncateLabels

// TruncateLabels clears "cached" labels on a topic
func TruncateLabels(topic *tat.Topic) error {
	err := store.Tat().CTopics.Update(
		bson.M{"_id": topic.ID},
		bson.M{"$unset": bson.M{"labels": ""}})

	cache.CleanTopicByName(topic.Topic)
	return err
}
开发者ID:ovh,项目名称:tat,代码行数:9,代码来源:topic.go


示例20: UpdateSystemUser

// UpdateSystemUser updates flags CanWriteNotifications and CanListUsersAsAdmin
func UpdateSystemUser(user *tat.User, canWriteNotifications, canListUsersAsAdmin bool) error {
	return store.Tat().CUsers.Update(
		bson.M{"_id": user.ID},
		bson.M{"$set": bson.M{
			"canWriteNotifications": canWriteNotifications,
			"canListUsersAsAdmin":   canListUsersAsAdmin,
		}})
}
开发者ID:ovh,项目名称:tat,代码行数:9,代码来源:user.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang models.Message类代码示例发布时间:2022-05-28
下一篇:
Golang test.TestTripperFactory类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap