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


Golang bson.ObjectId函数代码示例

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


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

示例1: FindGroupById

func (application Application) FindGroupById(id bson.ObjectId) (Group, bool) {
	result := Group{}
	query := bson.M{"_id": bson.ObjectId(id)}

	database.FindBy(application.Id.Hex()+"_groups", &result, query)

	return result, result.Id == bson.ObjectId("")
}
开发者ID:BlueprintProject,项目名称:Blueprint,代码行数:8,代码来源:group.go

示例2: To24bytesId

//Game
func (c *Game) To24bytesId() {
	if len(c.Id) == 12 {
		c.Id = bson.ObjectId(c.Id.Hex())
	}
	if len(c.OwnerId) == 12 {
		c.OwnerId = bson.ObjectId(c.OwnerId.Hex())
	}
}
开发者ID:otsimo,项目名称:integration-tests,代码行数:9,代码来源:util.go

示例3: User

func (s *AuthService) User(token string) (u bson.ObjectId, err error) {
	t, err := jwt.Parse(token, s.signFunc)
	if err != nil {
		return bson.ObjectId(""), err
	}

	if s.hasExpired(t) {
		return bson.ObjectId(""), &exceptions.TokenExpiredException{"Token is expired."}
	}

	return bson.ObjectIdHex(t.Claims["user"].(string)), nil
}
开发者ID:creativelikeadog,项目名称:go-taxi-api,代码行数:12,代码来源:auth.go

示例4: FilesGetHandler

func FilesGetHandler(c echo.Context) error {

	// Create the User Session
	session := session.NewSession(c)

	// Validate that the request signature is valid
	session.ValidateFileRequest()

	redirect := false

	if !session.AuthFailed {
		// Get the endpoint for that record
		endpoint := session.GetEndpoint()

		if plugin.CheckPlugin("get_file", endpoint) {
			plugin.RunPlugin("get_file", endpoint, session)
		} else {
			// Get the ID of the record that owns the file
			record_id := bson.ObjectIdHex(session.GetParam("record_id").(string))

			// Get the record from the endpoint collection
			record := endpoint.FindReadRecordById(record_id, session.User)

			// Check if the record exists
			if record.Id != bson.ObjectId("") {

				// Get the ID of the file
				file_id := bson.ObjectIdHex(session.GetParam("file_id").(string))

				// Get the file from the database
				file := record.FindFileById(file_id)

				// Validate that the file exists
				if file.Id != bson.ObjectId("") {

					// Redirect to the file path
					c.Redirect(301, file.DownloadURL())
					redirect = true

					// Log the request
					session.LogRequest()
				}
			}

			if !redirect {
				session.Write()
			}
		}
	}

	return nil
}
开发者ID:BlueprintProject,项目名称:Blueprint,代码行数:52,代码来源:files.go

示例5: persistRelation

func (self *DocumentBase) persistRelation(value reflect.Value, autoSave bool) (error, bson.ObjectId) {

	// Detect the type of the value which is stored within the slice
	switch typedValue := value.Interface().(type) {

	// Deserialize objects to id
	case IDocumentBase:
		{
			// Save children when flag is enabled
			if autoSave {
				err := typedValue.Save()

				if err != nil {
					return err, bson.ObjectId("")
				}
			}

			objectId := typedValue.GetId()

			if !objectId.Valid() {
				panic("DB: Can not persist the relation object because the child was not saved before (invalid id).")
			}

			return nil, objectId
		}

	// Only save the id
	case bson.ObjectId:
		{
			if !typedValue.Valid() {
				panic("DB: Can not persist the relation object because the child was not saved before (invalid id).")
			}

			return nil, typedValue
		}

	case string:
		{
			if !bson.IsObjectIdHex(typedValue) {
				return &InvalidIdError{&QueryError{fmt.Sprintf("Invalid id`s given")}}, bson.ObjectId("")
			} else {
				return nil, bson.ObjectIdHex(typedValue)
			}
		}

	default:
		{
			panic(fmt.Sprintf("DB: Only type 'bson.ObjectId' and 'IDocumentBase' can be stored in slices. You used %v", value.Interface()))
		}
	}
}
开发者ID:tuxago,项目名称:mongodm,代码行数:51,代码来源:document_base.go

示例6: GetSuperUser

func (application Application) GetSuperUser() User {
	result := User{}
	query := bson.M{"super_user": true}

	database.FindBy(application.Id.Hex()+"_users", &result, query)

	if result.Id == bson.ObjectId("") {
		result = User{}
		result.SuperUser = true
		result.ApplicationId = bson.ObjectId(application.Id)
		result.Save()
	}

	return result
}
开发者ID:BlueprintProject,项目名称:Blueprint,代码行数:15,代码来源:user.go

示例7: GetSessionGMId

func GetSessionGMId(req *http.Request) (bson.ObjectId, error) {
	if v, err := GetGMSessionValue(req, GM_ID_SESSION_KEY); err != nil || v == nil {
		return bson.ObjectId(""), errors.New("Invalid session id format")
	} else {
		if str, found := v.(string); found {
			if bson.IsObjectIdHex(str) {
				return bson.ObjectIdHex(str), nil
			} else {
				return bson.ObjectId(""), errors.New("Invalid session id format")
			}
		} else {
			return bson.ObjectId(""), errors.New("Invalid session id format")
		}
	}
}
开发者ID:mshockwave,项目名称:nthuaplus-backend,代码行数:15,代码来源:routines.go

示例8: IdFromBase64

func IdFromBase64(b64 string) Id {
	var dst = make([]byte, len(b64))
	if n, err := base64.URLEncoding.Decode(dst, []byte(b64)); err == nil {
		return Id{bson.ObjectId(dst[:n])}
	}
	return Id{}
}
开发者ID:zaolab,项目名称:sunnified,代码行数:7,代码来源:mvc.go

示例9: FindFeedItemById

func FindFeedItemById(id bson.ObjectId) (FeedItem, error) {
	var err error
	Col = Session.DB("test").C("FeedItem")
	feedItem := FeedItem{}
	err = Col.Find(bson.M{"_id": bson.ObjectId(id)}).One(&feedItem)
	return feedItem, err
}
开发者ID:joshheinrichs,项目名称:cmpt436-project,代码行数:7,代码来源:db.go

示例10: convertToObjectId

func convertToObjectId(id string) bson.ObjectId {
	objectIdFormat, err := hex.DecodeString(id)
	if err != nil || len(objectIdFormat) != 12 {
		panic(fmt.Sprintf("Invalid input to ObjectIdHex: %q", id))
	}
	return bson.ObjectId(objectIdFormat)
}
开发者ID:sonikaarora,项目名称:cmpe273-Assignment2,代码行数:7,代码来源:services.go

示例11: FindPaymentById

//Only can be one payment between two people
func FindPaymentById(id bson.ObjectId) (Payment, error) {
	var err error
	Col = Session.DB("test").C("Payment")
	payment := Payment{}
	err = Col.Find(bson.M{"_id": bson.ObjectId(id)}).One(&payment)
	return payment, err
}
开发者ID:joshheinrichs,项目名称:cmpt436-project,代码行数:8,代码来源:db.go

示例12: FindPurchaseById

func FindPurchaseById(id bson.ObjectId) (Purchase, error) {
	var err error
	Col = Session.DB("test").C("Purchase")
	purchase := Purchase{}
	err = Col.Find(bson.M{"_id": bson.ObjectId(id)}).One(&purchase)
	return purchase, err
}
开发者ID:joshheinrichs,项目名称:cmpt436-project,代码行数:7,代码来源:db.go

示例13: ExecuteCronTrigger

func (application Application) ExecuteCronTrigger() {
	result := findTriggerForApplicationIdAndEvent(application.Id, "cron")

	if result.Id != bson.ObjectId("") {
		result.Run(application.Id.Hex(), "")
	}
}
开发者ID:BlueprintProject,项目名称:Blueprint,代码行数:7,代码来源:trigger.go

示例14: CheckID

// CheckID converts string s to ObjectId if it is possible,
// otherwise it returns error.
func CheckID(s string) (bson.ObjectId, error) {
	d, err := hex.DecodeString(s)
	if err != nil || len(d) != 12 {
		return "", errors.New("invalid database ID")
	}
	return bson.ObjectId(d), nil
}
开发者ID:z0rr0,项目名称:luss,代码行数:9,代码来源:db.go

示例15: FindContact

func FindContact(id bson.ObjectId) (Contact, error) {
	var err error
	Col = Session.DB("test").C("Contact")
	contact := Contact{}
	err = Col.Find(bson.M{"_id": bson.ObjectId(id)}).One(&contact)
	return contact, err
}
开发者ID:joshheinrichs,项目名称:cmpt436-project,代码行数:7,代码来源:testConnections.go


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