本文整理汇总了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()
}
示例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
}