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


Golang IServices.ListByEnvID方法代碼示例

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


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

示例1: CmdStatus

func CmdStatus(envID string, is IStatus, ie environments.IEnvironments, iservices services.IServices) error {
	env, err := ie.Retrieve(envID)
	if err != nil {
		return err
	}
	svcs, err := iservices.ListByEnvID(env.ID, env.Pod)
	if err != nil {
		return err
	}
	return is.Status(env, svcs)
}
開發者ID:catalyzeio,項目名稱:cli,代碼行數:11,代碼來源:status.go

示例2: CmdAssociate

func CmdAssociate(envLabel, svcLabel, alias, remote string, defaultEnv bool, ia IAssociate, ig git.IGit, ie environments.IEnvironments, is services.IServices) error {
	if defaultEnv {
		logrus.Warnln("The \"--default\" flag has been deprecated! It will be removed in a future version.")
	}
	if !ig.Exists() {
		return errors.New("No git repo found in the current directory")
	}
	logrus.Printf("Existing git remotes named \"%s\" will be overwritten", remote)
	envs, errs := ie.List()
	if errs != nil && len(errs) > 0 {
		for pod, err := range errs {
			logrus.Debugf("Failed to list environments for pod \"%s\": %s", pod, err)
		}
	}
	var e *models.Environment
	var svcs *[]models.Service
	var err error
	for _, env := range *envs {
		if env.Name == envLabel {
			e = &env
			svcs, err = is.ListByEnvID(env.ID, env.Pod)
			if err != nil {
				return err
			}
			break
		}
	}
	if e == nil {
		return fmt.Errorf("No environment with name \"%s\" found", envLabel)
	}
	if svcs == nil {
		return fmt.Errorf("No services found for environment with name \"%s\"", envLabel)
	}

	var chosenService *models.Service
	availableCodeServices := []string{}
	for _, service := range *svcs {
		if service.Type == "code" {
			if service.Label == svcLabel {
				chosenService = &service
				break
			}
			availableCodeServices = append(availableCodeServices, service.Label)
		}
	}
	if chosenService == nil {
		return fmt.Errorf("No code service found with label \"%s\". Code services found: %s", svcLabel, strings.Join(availableCodeServices, ", "))
	}
	remotes, err := ig.List()
	if err != nil {
		return err
	}
	for _, r := range remotes {
		if r == remote {
			ig.Rm(remote)
			break
		}
	}
	err = ig.Add(remote, chosenService.Source)
	if err != nil {
		return err
	}
	logrus.Printf("\"%s\" remote added.", remote)

	name := alias
	if name == "" {
		name = envLabel
	}
	err = ia.Associate(name, remote, defaultEnv, e, chosenService)
	if err != nil {
		return err
	}
	logrus.Printf("Your git repository \"%s\" has been associated with code service \"%s\" and environment \"%s\"", remote, svcLabel, name)
	logrus.Println("After associating to an environment, you need to add a cert with the \"catalyze certs create\" command, if you have not done so already")
	return nil
}
開發者ID:catalyzeio,項目名稱:cli,代碼行數:76,代碼來源:associate.go


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