Exemple #1
0
func (self *MongoDatastore) Get(colName string, id string, result interface{}) error {
	if !bson.IsObjectIdHex(id) {
		return errors.New("invalid id format")
	}

	idObject := bson.ObjectIdHex(id)

	return self.Database().C(colName).FindId(idObject).One(result)
}
Exemple #2
0
func (s *S) TestIsObjectIdHex(c *C) {
	test := []struct {
		id    string
		valid bool
	}{
		{"4d88e15b60f486e428412dc9", true},
		{"4d88e15b60f486e428412dc", false},
		{"4d88e15b60f486e428412dc9e", false},
		{"4d88e15b60f486e428412dcx", false},
	}
	for _, t := range test {
		c.Assert(bson.IsObjectIdHex(t.id), Equals, t.valid)
	}
}