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


Golang Settings.PaasHost方法代码示例

本文整理汇总了Golang中github.com/catalyzeio/catalyze/models.Settings.PaasHost方法的典型用法代码示例。如果您正苦于以下问题:Golang Settings.PaasHost方法的具体用法?Golang Settings.PaasHost怎么用?Golang Settings.PaasHost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/catalyzeio/catalyze/models.Settings的用法示例。


在下文中一共展示了Settings.PaasHost方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GetSettings

// GetSettings returns a Settings object for the current context
func GetSettings(required bool, promptForEnv bool, envName string, baasHost string, paasHost string, username string, password string) *models.Settings {
	HomeDir, err := homedir.Dir()
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	file, err := os.Open(filepath.Join(HomeDir, SettingsFile))
	if os.IsNotExist(err) {
		file, err = os.Create(filepath.Join(HomeDir, SettingsFile))
	}
	defer file.Close()
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	var settings models.Settings
	json.NewDecoder(file).Decode(&settings)
	// would be best to default this to an initialized map rather than nil
	if settings.Environments == nil {
		settings.Environments = make(map[string]models.AssociatedEnv)
	}

	// try and set the given env first, if it exists
	if envName != "" {
		setGivenEnv(envName, &settings)
		if settings.EnvironmentID == "" || settings.ServiceID == "" {
			fmt.Printf("No environment named \"%s\" has been associated. Run \"catalyze associated\" to see what environments have been associated or run \"catalyze associate\" from a local git repo to create a new association\n", envName)
			os.Exit(1)
		}
	}

	// if no env name was given, try and fetch the local env
	if settings.EnvironmentID == "" || settings.ServiceID == "" {
		setLocalEnv(required, &settings)
	}

	// if its not there, fetch the default
	if settings.EnvironmentID == "" || settings.ServiceID == "" {
		setDefaultEnv(&settings)
	}

	// if no default, fetch the first associated env and print warning
	if settings.EnvironmentID == "" || settings.ServiceID == "" {
		// warn and ask
		setFirstAssociatedEnv(required, promptForEnv, &settings)
	}

	// if no env found, warn and quit
	if required && (settings.EnvironmentID == "" || settings.ServiceID == "") {
		fmt.Println("No Catalyze environment has been associated. Run \"catalyze associate\" from a local git repo first")
		os.Exit(1)
	}

	settings.BaasHost = baasHost
	settings.PaasHost = paasHost
	settings.Username = username
	settings.Password = password
	return &settings
}
开发者ID:jkoelndorfer,项目名称:cli,代码行数:61,代码来源:settings.go


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