本文整理匯總了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
}