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


Golang modelhelper.Initialize函数代码示例

本文整理汇总了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)
}
开发者ID:koding,项目名称:koding,代码行数:26,代码来源:group.go

示例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
}
开发者ID:koding,项目名称:koding,代码行数:26,代码来源:modeltesthelper.go


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