當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ClientStore.CurrentController方法代碼示例

本文整理匯總了Golang中github.com/juju/juju/jujuclient.ClientStore.CurrentController方法的典型用法代碼示例。如果您正苦於以下問題:Golang ClientStore.CurrentController方法的具體用法?Golang ClientStore.CurrentController怎麽用?Golang ClientStore.CurrentController使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/juju/juju/jujuclient.ClientStore的用法示例。


在下文中一共展示了ClientStore.CurrentController方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: GetCurrentModel

// GetCurrentModel returns the name of the current Juju model.
//
// If $JUJU_MODEL is set, use that. Otherwise, get the current
// controller from controllers.yaml, and then identify the current
// model for that controller in models.yaml. If there is no current
// controller, then an empty string is returned. It is not an error
// to have no current model.
//
// If there is a current controller, but no current model for that
// controller, then GetCurrentModel will return the string
// "<controller>:". If there is a current model as well, it will
// return "<controller>:<model>". Only when $JUJU_MODEL is set,
// will the result possibly be unqualified.
func GetCurrentModel(store jujuclient.ClientStore) (string, error) {
	if model := os.Getenv(osenv.JujuModelEnvKey); model != "" {
		return model, nil
	}

	currentController, err := store.CurrentController()
	if errors.IsNotFound(err) {
		return "", nil
	} else if err != nil {
		return "", errors.Trace(err)
	}

	currentModel, err := store.CurrentModel(currentController)
	if errors.IsNotFound(err) {
		return currentController + ":", nil
	} else if err != nil {
		return "", errors.Trace(err)
	}
	return JoinModelName(currentController, currentModel), nil
}
開發者ID:bac,項目名稱:juju,代碼行數:33,代碼來源:modelcommand.go


注:本文中的github.com/juju/juju/jujuclient.ClientStore.CurrentController方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。