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


Golang ObjectId.Hex方法代码示例

本文整理汇总了Golang中labix/org/v2/mgo/bson.ObjectId.Hex方法的典型用法代码示例。如果您正苦于以下问题:Golang ObjectId.Hex方法的具体用法?Golang ObjectId.Hex怎么用?Golang ObjectId.Hex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在labix/org/v2/mgo/bson.ObjectId的用法示例。


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

示例1: CanModifyComment

// Only called when doing update or delete.
// At inserting, user.OkayToDoAction is sufficient.
// This needs additional action: you can only update or delete a given comment only if it's yours (under a certain level).
func CanModifyComment(db *mgo.Database, inp map[string][]string, correction_level int, user_id bson.ObjectId, user_level int) error {
	rule := map[string]interface{}{
		"content_id": "must",
		"comment_id": "must",
		"type":       "must",
	}
	dat, err := extract.New(rule).Extract(inp)
	if err != nil {
		return err
	}
	// Even if he has the required level, and he is below correction_level, he can't modify other people's comment, only his owns.
	// So we query here the comment and check who is the owner of it.
	if user_level < correction_level {
		content_id_str := basic.StripId(dat["content_id"].(string))
		comment_id_str := basic.StripId(dat["comment_id"].(string))
		auth, err := findCommentAuthor(db, content_id_str, comment_id_str)
		if err != nil {
			return err
		}
		if auth.Hex() != user_id.Hex() {
			return fmt.Errorf("You are not the rightous owner of the comment.")
		}
	}
	return nil
}
开发者ID:Laller,项目名称:hypecms,代码行数:28,代码来源:comments.go

示例2: GetRead

func (c Blog) GetRead(id bson.ObjectId) revel.Result {
	if id.Hex() != "" {
		article := models.GetArticleByObjectId(c.MongoSession, id)
		return c.Render(article)
	}
	return c.NotFound("Invalid article Id.")
}
开发者ID:jango2015,项目名称:bloggo,代码行数:7,代码来源:blog.go

示例3: GetId

// Get document from id
func (s *session) GetId(col string, id bson.ObjectId, doc interface{}) error {
	c := s.db.C(col)
	err := c.FindId(id).One(doc)
	if err != nil {
		log.Printf("**ERROR: Could not lookup document with id %v from collection %v: %v", id.Hex(), col, err)
	}
	return err
}
开发者ID:raphael,项目名称:gotcha,代码行数:9,代码来源:mongo.go

示例4: AddSharedNote

// 添加共享d笔记
func (this *NoteService) AddSharedNote(note info.Note, myUserId bson.ObjectId) info.Note {
	// 判断我是否有权限添加
	if shareService.HasUpdateNotebookPerm(note.UserId.Hex(), myUserId.Hex(), note.NotebookId.Hex()) {
		note.CreatedUserId = myUserId // 是我给共享我的人创建的
		return this.AddNote(note)
	}
	return info.Note{}
}
开发者ID:jianping11,项目名称:leanote,代码行数:9,代码来源:NoteService.go

示例5: ObjectIdInSlice

// 查找ObjectId数组中是否有指定值.
func ObjectIdInSlice(id bson.ObjectId, list []bson.ObjectId) bool {
	for _, b := range list {
		if b.Hex() == id.Hex() {
			return true
		}
	}
	return false
}
开发者ID:nangong92t,项目名称:go_src,代码行数:9,代码来源:utils.go

示例6: backupServer

func backupServer(serverId string, backupTime time.Time) (err error) {
	wip := <-wipGen.C
	defer close(wip)

	server := servers.Get(serverId)
	if server == nil {
		err = errors.New(fmt.Sprintf("no server for %s", serverId))
		return
	}

	var (
		url  string
		size int64
	)
	err = retry(1000, 5*time.Second, func(retries int) error {
		var err error
		url, size, err = server.BackupWorld(backupTime)
		if err != nil {
			plog.Error(err, map[string]interface{}{
				"event":    "world_backup",
				"serverId": serverId,
				"retries":  retries,
			})
		}
		return err
	})
	if err != nil {
		return
	}

	var snapshotId bson.ObjectId
	err = retry(1000, 5*time.Second, func(retries int) error {
		var err error
		snapshotId, err = StoreBackupInMongo(serverId, url, size, backupTime)
		if err != nil {
			plog.Error(err, map[string]interface{}{
				"event":    "world_db_store",
				"serverId": serverId,
				"retries":  retries,
			})

		}
		return err
	})

	pushPinkyEvent(map[string]interface{}{
		"ts":          time.Now(),
		"server_id":   serverId,
		"event":       "server_event",
		"type":        "backed_up",
		"snapshot_id": snapshotId.Hex(),
		"url":         url,
		"size":        size,
	})

	return
}
开发者ID:minefold,项目名称:pinky,代码行数:57,代码来源:main.go

示例7: deleteImage

func (api *EventsApi) deleteImage(id bson.ObjectId) error {

	err := api.images.DeleteFile(api.images.GetBasePath() + string(os.PathSeparator) + id.Hex() + ".jpg")
	if err != nil {
		return err
	}

	api.imageCache.Remove(api.imageCache.FindKeys(id.Hex()))
	return nil
}
开发者ID:jhyle,项目名称:goevents,代码行数:10,代码来源:api.go

示例8: Authenticate

//-------------------------------------------------------
// methods
//-------------------------------------------------------
// obtain all the data and proceed to authorisation
func (d *Daemon) Authenticate(id bson.ObjectId) error {
	c := db.C("daemons")
	err := c.FindId(id).One(&d.Entry)
	if err == nil {
		d.Id = id.Hex()
		d.OrgId = d.Entry.OrgId.Hex()
		return d.Authorise()
	}
	return err
}
开发者ID:GU-2013-TEAM-M,项目名称:eos,代码行数:14,代码来源:daemon.go

示例9: mapFromFeed

func mapFromFeed(feed *domain.Feed) feedDao {
	var id bson.ObjectId
	if len(feed.ID) > 0 {
		id = bson.ObjectIdHex(feed.ID)
	} else {
		id = bson.NewObjectId()
		feed.ID = id.Hex()
	}
	return feedDao{id, feed.Uri, feed.LastSync}
}
开发者ID:josselinauguste,项目名称:armagnac,代码行数:10,代码来源:feed_repository_mongodb.go

示例10: Authenticate

//-------------------------------------------------------
// methods
//-------------------------------------------------------
// obtain all the data and proceed to authorisation
func (u *User) Authenticate(id bson.ObjectId) error {
	c := db.C("users")
	err := c.FindId(id).One(&u.Entry)
	if err == nil {
		u.Id = id.Hex()
		u.OrgId = u.Entry.OrgId.Hex()
		return u.Authorise()
	}
	return err
}
开发者ID:GU-2013-TEAM-M,项目名称:eos,代码行数:14,代码来源:user.go

示例11: ObjectIdIsIn

// 检测ObjectId数组中是否存在某一个id。
func ObjectIdIsIn(ids []bson.ObjectId, id bson.ObjectId) bool {
	result := false
	for i := 0; i < len(ids); i++ {
		if ids[i].Hex() == id.Hex() {
			result = true
			break
		}
	}

	return result
}
开发者ID:nangong92t,项目名称:go_src,代码行数:12,代码来源:utils.go

示例12: GetUpdate

func (c User) GetUpdate(id bson.ObjectId) revel.Result {
	if c.ActiveUser != nil {
		action := "/User/" + id.Hex()
		user := c.ActiveUser
		if user.CanBeUpdatedBy(c.MongoSession, c.ActiveUser) {
			return c.Render(action, user)
		}
		return c.Forbidden("You are not allowed to edit this resource.")
	}
	return c.Redirect(User.GetLogin)
}
开发者ID:jango2015,项目名称:bloggo,代码行数:11,代码来源:user.go

示例13: SetBSON

// Implements bson.Setter for mongo.Ref compatibility.
// Yes this bson dependency is dirty, but necessary
// for transition form mongo.Ref to model.Ref.
func (self *Ref) SetBSON(raw bson.Raw) error {
	var objectId *bson.ObjectId
	if raw.Unmarshal(&objectId) == nil {
		if objectId != nil {
			*self = Ref(objectId.Hex())
		} else {
			*self = ""
		}
		return nil
	}
	return raw.Unmarshal(self)
}
开发者ID:mda747,项目名称:go-start,代码行数:15,代码来源:ref.go

示例14: CheckForId

func (table *mongoTable) CheckForId(id bson.ObjectId) error {

	count, err := table.CountById(id)
	if err != nil {
		return err
	}

	if count == 1 {
		return nil
	} else {
		return errors.New(table.collection.Name + " " + id.Hex() + " not found.")
	}
}
开发者ID:jhyle,项目名称:goevents,代码行数:13,代码来源:persistence.go

示例15: Login

// Sets a cookie to w named "user" with a value of the encoded user_id.
// Admins, guests, registered users, everyone logs in with this.
func Login(w http.ResponseWriter, user_id bson.ObjectId, block_key []byte) error {
	id_b, err := encryptStr(block_key, user_id.Hex())
	if err != nil {
		return err
	}
	encoded_id := string(id_b)
	c := &http.Cookie{
		Name:   "user",
		Value:  encoded_id,
		MaxAge: 3600000,
		Path:   "/",
	}
	http.SetCookie(w, c)
	return nil
}
开发者ID:Laller,项目名称:hypecms,代码行数:17,代码来源:user_model.go


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