• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang services.IServices类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/catalyzeio/cli/commands/services.IServices的典型用法代码示例。如果您正苦于以下问题:Golang IServices类的具体用法?Golang IServices怎么用?Golang IServices使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: CmdList

func CmdList(databaseName string, page, pageSize int, id IDb, is services.IServices) error {
	service, err := is.RetrieveByLabel(databaseName)
	if err != nil {
		return err
	}
	if service == nil {
		return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", databaseName)
	}
	jobs, err := id.List(page, pageSize, service)
	if err != nil {
		return err
	}
	sort.Sort(SortedJobs(*jobs))
	for _, job := range *jobs {
		logrus.Printf("%s %s (status = %s)", job.ID, job.CreatedAt, job.Status)
	}
	if len(*jobs) == pageSize && page == 1 {
		logrus.Println("(for older backups, try with --page 2 or adjust --page-size)")
	}
	if len(*jobs) == 0 && page == 1 {
		logrus.Println("No backups created yet for this service.")
	} else if len(*jobs) == 0 {
		logrus.Println("No backups found with the given parameters.")
	}
	return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:26,代码来源:list.go


示例2: CmdDeploy

func CmdDeploy(svcName, target string, iw IWorker, is services.IServices, ij jobs.IJobs) error {
	service, err := is.RetrieveByLabel(svcName)
	if err != nil {
		return err
	}
	if service == nil {
		return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services list\" command.", svcName)
	}
	logrus.Printf("Initiating a worker for service %s (procfile target = \"%s\")", svcName, target)
	workers, err := iw.Retrieve(service.ID)
	if err != nil {
		return err
	}
	if _, ok := workers.Workers[target]; ok {
		logrus.Printf("Worker with target %s for service %s is already running, deploying another worker", target, svcName)
	}
	workers.Workers[target]++
	err = iw.Update(service.ID, workers)
	if err != nil {
		return err
	}
	err = ij.DeployTarget(target, service.ID)
	if err != nil {
		return err
	}
	logrus.Printf("Successfully deployed a worker for service %s with target %s", svcName, target)
	return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:28,代码来源:deploy.go


示例3: CmdShow

func CmdShow(name string, is ISites, iservices services.IServices) error {
	serviceProxy, err := iservices.RetrieveByLabel("service_proxy")
	if err != nil {
		return err
	}
	sites, err := is.List(serviceProxy.ID)
	if err != nil {
		return err
	}
	var site *models.Site
	for _, s := range *sites {
		if s.Name == name {
			site = &s
			break
		}
	}
	if site == nil {
		return fmt.Errorf("Could not find a site with the label \"%s\". You can list sites with the \"catalyze sites list\" command.", name)
	}
	site, err = is.Retrieve(site.ID, serviceProxy.ID)
	if err != nil {
		return err
	}
	table, err := simpletable.New(simpletable.HeadersForType(models.Site{}), []models.Site{*site})
	if err != nil {
		return err
	}
	table.Write(logrus.StandardLogger().Out)
	return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:30,代码来源:show.go


示例4: CmdAdd

func CmdAdd(name, keyPath, svcName string, id IDeployKeys, is services.IServices) error {
	if strings.ContainsAny(name, config.InvalidChars) {
		return fmt.Errorf("Invalid SSH key name. Names must not contain the following characters: %s", config.InvalidChars)
	}
	if _, err := os.Stat(keyPath); os.IsNotExist(err) {
		return fmt.Errorf("A file does not exist at path '%s'", keyPath)
	}
	service, err := is.RetrieveByLabel(svcName)
	if err != nil {
		return err
	}
	if service == nil {
		return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", svcName)
	}
	if service.Type != "code" {
		return fmt.Errorf("You can only add deploy keys to code services, not %s services", service.Type)
	}
	key, err := ioutil.ReadFile(keyPath)
	if err != nil {
		return err
	}
	k, err := id.ParsePublicKey(key)
	if err != nil {
		return err
	}
	key = ssh.MarshalAuthorizedKey(k)
	return id.Add(name, "ssh", string(key), service.ID)
}
开发者ID:catalyzeio,项目名称:cli,代码行数:28,代码来源:add.go


示例5: CmdBackup

func CmdBackup(databaseName string, skipPoll bool, id IDb, is services.IServices, ij jobs.IJobs) error {
	service, err := is.RetrieveByLabel(databaseName)
	if err != nil {
		return err
	}
	if service == nil {
		return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", databaseName)
	}
	job, err := id.Backup(service)
	if err != nil {
		return err
	}
	logrus.Printf("Backup started (job ID = %s)", job.ID)
	if !skipPoll {
		// all because logrus treats print, println, and printf the same
		logrus.StandardLogger().Out.Write([]byte("Polling until backup finishes."))
		status, err := ij.PollTillFinished(job.ID, service.ID)
		if err != nil {
			return err
		}
		job.Status = status
		logrus.Printf("\nEnded in status '%s'", job.Status)
		err = id.DumpLogs("backup", job, service)
		if err != nil {
			return err
		}
		if job.Status != "finished" {
			return fmt.Errorf("Job finished with invalid status %s", job.Status)
		}
	}
	logrus.Printf("You can download your backup with the \"catalyze db download %s %s ./output_file_path\" command", databaseName, job.ID)
	return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:33,代码来源:backup.go


示例6: CmdSet

func CmdSet(svcName, defaultSvcID string, variables []string, iv IVars, is services.IServices) error {
	if svcName != "" {
		service, err := is.RetrieveByLabel(svcName)
		if err != nil {
			return err
		}
		if service == nil {
			return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", svcName)
		}
		defaultSvcID = service.ID
	}
	envVarsMap := make(map[string]string, len(variables))
	r := regexp.MustCompile("^[a-zA-Z_]+[a-zA-Z0-9_]*$")
	for _, envVar := range variables {
		pieces := strings.SplitN(envVar, "=", 2)
		if len(pieces) != 2 {
			return fmt.Errorf("Invalid variable format. Expected <key>=<value> but got %s", envVar)
		}
		name, value := pieces[0], pieces[1]
		if !r.MatchString(name) {
			return fmt.Errorf("Invalid environment variable name '%s'. Environment variable names must only contain letters, numbers, and underscores and must not start with a number.", name)
		}
		envVarsMap[name] = value
	}

	err := iv.Set(defaultSvcID, envVarsMap)
	if err != nil {
		return err
	}
	// TODO add in the service label in the redeploy example once we take in the service label in
	// this command
	logrus.Println("Set. For these environment variables to take effect, you will need to redeploy your service with \"catalyze redeploy\"")
	return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:34,代码来源:set.go


示例7: CmdRollback

func CmdRollback(svcName, releaseName string, ij jobs.IJobs, irs releases.IReleases, is services.IServices) error {
	if strings.ContainsAny(releaseName, config.InvalidChars) {
		return fmt.Errorf("Invalid release name. Names must not contain the following characters: %s", config.InvalidChars)
	}
	service, err := is.RetrieveByLabel(svcName)
	if err != nil {
		return err
	}
	if service == nil {
		return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", svcName)
	}
	logrus.Printf("Rolling back %s to %s", svcName, releaseName)
	release, err := irs.Retrieve(releaseName, service.ID)
	if err != nil {
		return err
	}
	if release == nil {
		return fmt.Errorf("Could not find a release with the name \"%s\". You can list releases for this code service with the \"catalyze releases list %s\" command.", releaseName, svcName)
	}
	err = ij.DeployRelease(releaseName, service.ID)
	if err != nil {
		return err
	}
	logrus.Println("Rollback successful! Check the status with \"catalyze status\" and your logging dashboard for updates.")
	return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:26,代码来源:rollback.go


示例8: CmdDomain

// CmdDomain prints out the namespace plus domain of the given environment
func CmdDomain(envID string, ie environments.IEnvironments, is services.IServices, isites sites.ISites) error {
	env, err := ie.Retrieve(envID)
	if err != nil {
		return err
	}
	serviceProxy, err := is.RetrieveByLabel("service_proxy")
	if err != nil {
		return err
	}
	sites, err := isites.List(serviceProxy.ID)
	if err != nil {
		return err
	}
	domain := ""
	for _, site := range *sites {
		if strings.HasPrefix(site.Name, env.Namespace) {
			domain = site.Name
		}
	}
	if domain == "" {
		return errors.New("Could not determine the temporary domain name of your environment")
	}
	logrus.Println(domain)
	return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:26,代码来源:domain.go


示例9: CmdRm

func CmdRm(svcName, target string, iw IWorker, is services.IServices, ip prompts.IPrompts, ij jobs.IJobs) error {
	service, err := is.RetrieveByLabel(svcName)
	if err != nil {
		return err
	}
	if service == nil {
		return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services list\" command.", svcName)
	}
	err = ip.YesNo(fmt.Sprintf("Removing the worker target %s for service %s will automatically stop all existing worker jobs with that target, would you like to proceed? (y/n) ", target, svcName))
	if err != nil {
		return err
	}
	jobs, err := ij.RetrieveByTarget(service.ID, target, 1, 1000)
	if err != nil {
		return err
	}
	for _, j := range *jobs {
		err = ij.Delete(j.ID, service.ID)
		if err != nil {
			return err
		}
	}
	workers, err := iw.Retrieve(service.ID)
	if err != nil {
		return err
	}
	delete(workers.Workers, target)
	err = iw.Update(service.ID, workers)
	if err != nil {
		return err
	}
	logrus.Printf("Successfully removed all workers with target %s for service %s", target, svcName)
	return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:34,代码来源:rm.go


示例10: CmdDownload

func CmdDownload(databaseName, backupID, filePath string, force bool, id IDb, ip prompts.IPrompts, is services.IServices) error {
	err := ip.PHI()
	if err != nil {
		return err
	}
	if !force {
		if _, err := os.Stat(filePath); err == nil {
			return fmt.Errorf("File already exists at path '%s'. Specify `--force` to overwrite", filePath)
		}
	} else {
		os.Remove(filePath)
	}
	service, err := is.RetrieveByLabel(databaseName)
	if err != nil {
		return err
	}
	if service == nil {
		return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", databaseName)
	}
	err = id.Download(backupID, filePath, service)
	if err != nil {
		return err
	}
	logrus.Printf("%s backup downloaded successfully to %s", databaseName, filePath)
	logrus.Printf("You can also view logs for this backup with the \"catalyze db logs %s %s\" command", databaseName, backupID)
	return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:27,代码来源:download.go


示例11: CmdImport

func CmdImport(databaseName, filePath, mongoCollection, mongoDatabase string, id IDb, is services.IServices, ij jobs.IJobs) error {
	if _, err := os.Stat(filePath); os.IsNotExist(err) {
		return fmt.Errorf("A file does not exist at path '%s'", filePath)
	}
	service, err := is.RetrieveByLabel(databaseName)
	if err != nil {
		return err
	}
	if service == nil {
		return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", databaseName)
	}
	logrus.Printf("Backing up \"%s\" before performing the import", databaseName)
	job, err := id.Backup(service)
	if err != nil {
		return err
	}
	logrus.Printf("Backup started (job ID = %s)", job.ID)

	// all because logrus treats print, println, and printf the same
	logrus.StandardLogger().Out.Write([]byte("Polling until backup finishes."))
	status, err := ij.PollTillFinished(job.ID, service.ID)
	if err != nil {
		return err
	}
	job.Status = status
	logrus.Printf("\nEnded in status '%s'", job.Status)
	err = id.DumpLogs("backup", job, service)
	if err != nil {
		return err
	}
	if job.Status != "finished" {
		return fmt.Errorf("Job finished with invalid status %s", job.Status)
	}
	logrus.Printf("Importing '%s' into %s (ID = %s)", filePath, databaseName, service.ID)
	job, err = id.Import(filePath, mongoCollection, mongoDatabase, service)
	if err != nil {
		return err
	}
	// all because logrus treats print, println, and printf the same
	logrus.StandardLogger().Out.Write([]byte(fmt.Sprintf("Processing import (job ID = %s).", job.ID)))

	status, err = ij.PollTillFinished(job.ID, service.ID)
	if err != nil {
		return err
	}
	job.Status = status
	logrus.Printf("\nImport complete (end status = '%s')", job.Status)
	err = id.DumpLogs("restore", job, service)
	if err != nil {
		return err
	}
	if job.Status != "finished" {
		return fmt.Errorf("Finished with invalid status %s", job.Status)
	}
	return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:56,代码来源:import.go


示例12: CmdConsole

func CmdConsole(svcName, command string, ic IConsole, is services.IServices) error {
	service, err := is.RetrieveByLabel(svcName)
	if err != nil {
		return err
	}
	if service == nil {
		return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.\n", svcName)
	}
	return ic.Open(command, service)
}
开发者ID:catalyzeio,项目名称:cli,代码行数:10,代码来源:console.go


示例13: 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


示例14: CmdWorker

func CmdWorker(svcName, defaultSvcID, target string, iw IWorker, is services.IServices, ij jobs.IJobs) error {
	if svcName != "" {
		service, err := is.RetrieveByLabel(svcName)
		if err != nil {
			return err
		}
		if service == nil {
			return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services list\" command.", svcName)
		}
		svcName = service.Label
	}
	return CmdDeploy(svcName, target, iw, is, ij)
}
开发者ID:catalyzeio,项目名称:cli,代码行数:13,代码来源:worker.go


示例15: CmdLogs

func CmdLogs(databaseName, backupID string, id IDb, is services.IServices, ij jobs.IJobs) error {
	service, err := is.RetrieveByLabel(databaseName)
	if err != nil {
		return err
	}
	if service == nil {
		return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", databaseName)
	}
	job, err := ij.Retrieve(backupID, service.ID, false)
	if err != nil {
		return err
	}
	return id.DumpLogs("backup", job, service)
}
开发者ID:catalyzeio,项目名称:cli,代码行数:14,代码来源:logs.go


示例16: CmdExport

func CmdExport(databaseName, filePath string, force bool, id IDb, ip prompts.IPrompts, is services.IServices, ij jobs.IJobs) error {
	err := ip.PHI()
	if err != nil {
		return err
	}
	if !force {
		if _, err := os.Stat(filePath); err == nil {
			return fmt.Errorf("File already exists at path '%s'. Specify `--force` to overwrite", filePath)
		}
	} else {
		os.Remove(filePath)
	}
	service, err := is.RetrieveByLabel(databaseName)
	if err != nil {
		return err
	}
	if service == nil {
		return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", databaseName)
	}
	job, err := id.Backup(service)
	if err != nil {
		return err
	}
	logrus.Printf("Export started (job ID = %s)", job.ID)
	// all because logrus treats print, println, and printf the same
	logrus.StandardLogger().Out.Write([]byte("Polling until export finishes."))
	status, err := ij.PollTillFinished(job.ID, service.ID)
	if err != nil {
		return err
	}
	job.Status = status
	logrus.Printf("\nEnded in status '%s'", job.Status)
	if job.Status != "finished" {
		id.DumpLogs("backup", job, service)
		return fmt.Errorf("Job finished with invalid status %s", job.Status)
	}

	err = id.Export(filePath, job, service)
	if err != nil {
		return err
	}
	err = id.DumpLogs("backup", job, service)
	if err != nil {
		return err
	}
	logrus.Printf("%s exported successfully to %s", service.Name, filePath)
	return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:48,代码来源:export.go


示例17: CmdCreate

func CmdCreate(hostname, pubKeyPath, privKeyPath string, selfSigned, resolve bool, ic ICerts, is services.IServices, issl ssl.ISSL) error {
	if strings.ContainsAny(hostname, config.InvalidChars) {
		return fmt.Errorf("Invalid cert hostname. Hostnames must not contain the following characters: %s", config.InvalidChars)
	}
	if _, err := os.Stat(pubKeyPath); os.IsNotExist(err) {
		return fmt.Errorf("A cert does not exist at path '%s'", pubKeyPath)
	}
	if _, err := os.Stat(privKeyPath); os.IsNotExist(err) {
		return fmt.Errorf("A private key does not exist at path '%s'", privKeyPath)
	}
	err := issl.Verify(pubKeyPath, privKeyPath, hostname, selfSigned)
	var pubKeyBytes []byte
	var privKeyBytes []byte
	if err != nil && !ssl.IsHostnameMismatchErr(err) {
		if ssl.IsIncompleteChainErr(err) && resolve {
			pubKeyBytes, err = issl.Resolve(pubKeyPath)
			if err != nil {
				return fmt.Errorf("Could not resolve the incomplete certificate chain. If this is a self signed certificate, please re-run this command with the '-s' option: %s", err.Error())
			}
		} else {
			return err
		}
	}
	service, err := is.RetrieveByLabel("service_proxy")
	if err != nil {
		return err
	}
	if pubKeyBytes == nil {
		pubKeyBytes, err = ioutil.ReadFile(pubKeyPath)
		if err != nil {
			return err
		}
	}
	if privKeyBytes == nil {
		privKeyBytes, err = ioutil.ReadFile(privKeyPath)
		if err != nil {
			return err
		}
	}
	err = ic.Create(hostname, string(pubKeyBytes), string(privKeyBytes), service.ID)
	if err != nil {
		return err
	}
	logrus.Printf("Created '%s'", hostname)
	logrus.Println("To make use of your cert, you need to add a site with the \"catalyze sites create\" command")
	return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:47,代码来源:create.go


示例18: CmdRake

func CmdRake(svcName, taskName, defaultSvcID string, ir IRake, is services.IServices) error {
	if svcName != "" {
		service, err := is.RetrieveByLabel(svcName)
		if err != nil {
			return err
		}
		if service == nil {
			return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", svcName)
		}
		defaultSvcID = service.ID
	}
	logrus.Printf("Executing Rake task: %s", taskName)
	err := ir.Run(taskName, defaultSvcID)
	if err != nil {
		return err
	}
	logrus.Println("Rake task output viewable in your logging dashboard")
	return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:19,代码来源:rake.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang httpclient.ConvertResp函数代码示例发布时间:2022-05-23
下一篇:
Golang models.Settings类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap