當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。