當前位置: 首頁>>代碼示例>>Golang>>正文


Golang modelhelper.GetGroup函數代碼示例

本文整理匯總了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")
	}
}
開發者ID:koding,項目名稱:koding,代碼行數:28,代碼來源:group_test.go

示例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
}
開發者ID:koding,項目名稱:koding,代碼行數:35,代碼來源:group.go

示例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
}
開發者ID:koding,項目名稱:koding,代碼行數:14,代碼來源:builder.go


注:本文中的koding/db/mongodb/modelhelper.GetGroup函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。