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


Golang modelhelper.Close函数代码示例

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


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

示例1: Run

func (cmd *GroupFixDomain) Run(ctx context.Context) error {
	modelhelper.Initialize(envMongoURL())
	defer modelhelper.Close()

	merr := new(multierror.Error)
	users := cmd.values

	for len(users) > 0 {
		var batch []string
		var records []*dnsclient.Record
		var ids []bson.ObjectId
		n := min(len(users), 100)
		batch, users = users[:n], users[n:]

		DefaultUi.Info(fmt.Sprintf("checking %d records...", n))

		for _, user := range batch {
			rec, id, err := cmd.fixDomain(user)
			if err != nil {
				merr = multierror.Append(merr, err)
				continue
			}

			if cmd.dry {
				if rec == nil {
					merr = multierror.Append(merr, fmt.Errorf("domain for %q is ok", user))
				} else {
					merr = multierror.Append(merr, fmt.Errorf("domain for %q is going to be upserted without -dry: %q", user, rec.Name))
				}

				continue
			}

			if rec == nil {
				continue
			}

			records = append(records, rec)
			ids = append(ids, id)
		}

		if len(records) == 0 {
			continue
		}

		DefaultUi.Info(fmt.Sprintf("going to upsert %d domains", len(records)))

		// upsert domains
		if err := cmd.dns.UpsertRecords(records...); err != nil {
			merr = multierror.Append(merr, err)
		}

		// update domains
		if err := cmd.update(records, ids); err != nil {
			merr = multierror.Append(merr, err)
		}
	}

	return merr.ErrorOrNil()
}
开发者ID:koding,项目名称:koding,代码行数:60,代码来源:group.go

示例2: Action

func (m *Migrate) Action(args []string) error {
	if err := m.Valid(); err != nil {
		return err
	}

	c, err := kloudClient()
	if err != nil {
		return err
	}
	defer c.Close()

	modelhelper.Initialize(*m.MongoURL)
	defer modelhelper.Close()

	account, err := modelhelper.GetAccount(*m.User)
	if err != nil {
		return err
	}

	if *m.Credential == "" {
		*m.Credential = bson.NewObjectId().Hex()

		cred := &models.Credential{
			Id:         bson.NewObjectId(),
			Provider:   "aws",
			Identifier: *m.Credential,
			OriginId:   account.Id,
		}

		credData := &models.CredentialData{
			Id:         bson.NewObjectId(),
			Identifier: *m.Credential,
			OriginId:   account.Id,
			Meta: bson.M{
				"access_key": *m.Key,
				"secret_key": *m.Secret,
				"region":     *m.Region,
			},
		}

		if err := modelhelper.InsertCredential(cred, credData); err != nil {
			return err
		}

		credRelationship := &models.Relationship{
			Id:         bson.NewObjectId(),
			TargetId:   cred.Id,
			TargetName: "JCredential",
			SourceId:   account.Id,
			SourceName: "JAccount",
			As:         "owner",
		}

		if err := modelhelper.AddRelationship(credRelationship); err != nil {
			return err
		}
	}

	req := &MigrateRequest{
		Provider:    "aws",
		Machines:    m.Machines,
		Identifier:  *m.Credential,
		GroupName:   *m.Team,
		StackName:   "Migrated Stack",
		Impersonate: *m.User,
	}

	_, err = c.Tell("migrate", req)

	return err
}
开发者ID:koding,项目名称:koding,代码行数:71,代码来源:migrate.go


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