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


Golang store.Tat函数代码示例

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


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


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