本文整理汇总了Golang中koding/db/mongodb/modelhelper.GetGroup函数的典型用法代码示例。如果您正苦于以下问题:Golang GetGroup函数的具体用法?Golang GetGroup怎么用?Golang GetGroup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetGroup函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestCreateAndGetGroup
func TestCreateAndGetGroup(t *testing.T) {
db := modeltesthelper.NewMongoDB(t)
defer db.Close()
g, err := createGroup()
if err != nil {
t.Fatalf(err.Error())
}
g2, err := modelhelper.GetGroup(g.Slug)
if err != nil {
t.Errorf(err.Error())
}
if g2 == nil {
t.Errorf("couldnt fetch group by its slug. Got nil, expected: %+v", g)
}
if g2.Id.Hex() != g.Id.Hex() {
t.Errorf("groups are not same: expected: %+v, got: %+v ", g.Id.Hex(), g2.Id.Hex())
}
randomName := bson.NewObjectId().Hex()
_, err = modelhelper.GetGroup(randomName)
if err == nil {
t.Errorf("we should not be able to find the group")
}
}
示例2: details
func (cmd *GroupStack) details(username string) (*modelhelper.StackDetails, error) {
user, err := modelhelper.GetUser(username)
if err != nil {
return nil, fmt.Errorf("unable to find a user %q: %s", username, err)
}
group, err := modelhelper.GetGroup(cmd.groupSlug)
if err != nil {
return nil, fmt.Errorf("unable to find a group %q: %s", cmd.groupSlug, err)
}
machine, err := modelhelper.GetMachineBySlug(user.ObjectId, cmd.machineSlug)
if err != nil {
return nil, fmt.Errorf("unable to find a machine slug=%q, userID=%q: %s", cmd.machineSlug, user.ObjectId.Hex(), err)
}
account, err := modelhelper.GetAccount(username)
if err != nil {
return nil, fmt.Errorf("unable to find an account for %q: %s", username, err)
}
sd := &modelhelper.StackDetails{
UserID: user.ObjectId,
AccountID: account.Id,
GroupID: group.Id,
UserName: user.Name,
GroupSlug: group.Slug,
MachineID: machine.ObjectId,
BaseID: bson.ObjectIdHex(cmd.baseID),
}
return sd, nil
}
示例3: BuildTeam
// BuildTeam fetches team details from MongoDB.
//
// When it returns with nil error, the b.Team field is
// guranteed to be non-nil.
func (b *Builder) BuildTeam(team string) error {
g, err := modelhelper.GetGroup(team)
if err != nil {
return err
}
b.Team = g
return nil
}