本文整理汇总了Golang中koding/db/mongodb/modelhelper.Initialize函数的典型用法代码示例。如果您正苦于以下问题:Golang Initialize函数的具体用法?Golang Initialize怎么用?Golang Initialize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Initialize函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Run
func (cmd *GroupDelete) Run(ctx context.Context) error {
modelhelper.Initialize(envMongoURL())
defer modelhelper.Close()
entries, err := cmd.listEntries(ctx, cmd.filter())
if err != nil {
return err
}
items := make([]Item, len(entries))
for i, entry := range entries {
items[i] = &Instance{
SoftlayerID: entry.ID,
Domain: entry.Tags["koding-domain"],
Username: entry.Tags["koding-user"],
}
}
// TODO(rjeczalik): It's not possible to concurrently delete domains due to:
//
// ERROR could not delete domain "ukhscbd6fee9.kloudctl.dev.koding.io":
// PriorRequestNotComplete: The request was rejected because Route 53 was
// still processing a prior request.\n\tstatus code: 400, request id:
// c8248760-b2e5-11e5-9b7d-33010efc6afe"
//
cmd.GroupThrottler.throttle = 1
return cmd.RunItems(ctx, items)
}
示例2: NewMongoDB
// NewMongoDB looks up environment variables for mongo configuration URL. If
// configuration is found, this function creates a new session and replaces
// modeltesthelper Mongo singleton. If not, fails the test.
//
// Test will Fatal if connection to database is broken.
func NewMongoDB(t *testing.T) *MongoDB {
var mongoURL string
for _, mongoEnv := range mongoEnvs {
if mongoURL = os.Getenv(mongoEnv); mongoURL != "" {
break
}
}
if mongoURL == "" {
t.Fatalf("mongodb: one of env variables must be set: %s", strings.Join(mongoEnvs, ", "))
}
modelhelper.Initialize(mongoURL)
m := &MongoDB{DB: modelhelper.Mongo}
if err := m.DB.Session.Ping(); err != nil {
t.Fatalf("mongodb: cannot connect to %s: %v", mongoURL, err)
}
return m
}