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

Golang utils.StringInSlice函数代码示例

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

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



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

示例1: ListPools

func (r *RedisBackend) ListPools(env string) ([]string, error) {
	// This is the host entry created by commander
	// when it starts up.  It can dynamically create
	// a pool
	key := path.Join(env, "*", "hosts", "*", "info")
	keys, err := r.Keys(key)
	if err != nil {
		return nil, err
	}

	pools := []string{}

	for _, k := range keys {
		parts := strings.Split(k, "/")
		pool := parts[1]
		if !utils.StringInSlice(pool, pools) {
			pools = append(pools, pool)
		}
	}

	// This is the pools that have been manually created.  It's
	// possible to assign an app to a pool that has no running
	// hosts so we add these to the pools list as well.
	key = path.Join(env, "pools", "*")
	keys, err = r.Keys(key)
	if err != nil {
		return nil, err
	}

	for _, k := range keys {
		parts := strings.Split(k, "/")
		pool := parts[2]

		if pool != "*" {
			continue
		}

		members, err := r.Members(k)
		if err != nil {
			return nil, err
		}

		for _, m := range members {
			if !utils.StringInSlice(m, pools) {
				pools = append(pools, m)
			}
		}
	}

	return pools, nil
}
开发者ID:zombor,项目名称:galaxy,代码行数:51,代码来源:redis.go


示例2: RuntimeSet

func RuntimeSet(configStore *config.Store, app, env, pool string, options RuntimeOptions) (bool, error) {

	cfg, err := configStore.GetApp(app, env)
	if err != nil {
		return false, err
	}

	if options.Ps != 0 && options.Ps != cfg.GetProcesses(pool) {
		cfg.SetProcesses(pool, options.Ps)
	}

	if options.Memory != "" && options.Memory != cfg.GetMemory(pool) {
		cfg.SetMemory(pool, options.Memory)
	}

	vhosts := []string{}
	vhostsFromEnv := cfg.Env()["VIRTUAL_HOST"]
	if vhostsFromEnv != "" {
		vhosts = strings.Split(cfg.Env()["VIRTUAL_HOST"], ",")
	}

	if options.VirtualHost != "" && !utils.StringInSlice(options.VirtualHost, vhosts) {
		vhosts = append(vhosts, options.VirtualHost)
		cfg.EnvSet("VIRTUAL_HOST", strings.Join(vhosts, ","))
	}

	if options.Port != "" {
		cfg.EnvSet("GALAXY_PORT", options.Port)
	}

	return configStore.UpdateApp(cfg, env)
}
开发者ID:zombor,项目名称:galaxy,代码行数:32,代码来源:runtime.go


示例3: RuntimeUnset

func RuntimeUnset(configStore *config.Store, app, env, pool string, options RuntimeOptions) (bool, error) {

	cfg, err := configStore.GetApp(app, env)
	if err != nil {
		return false, err
	}

	if options.Ps != 0 {
		cfg.SetProcesses(pool, -1)
	}

	if options.Memory != "" {
		cfg.SetMemory(pool, "")
	}

	vhosts := strings.Split(cfg.Env()["VIRTUAL_HOST"], ",")
	if options.VirtualHost != "" && utils.StringInSlice(options.VirtualHost, vhosts) {
		vhosts = utils.RemoveStringInSlice(options.VirtualHost, vhosts)
		cfg.EnvSet("VIRTUAL_HOST", strings.Join(vhosts, ","))
	}

	if options.Port != "" {
		cfg.EnvSet("GALAXY_PORT", "")
	}

	return configStore.UpdateApp(cfg, env)
}
开发者ID:zombor,项目名称:galaxy,代码行数:27,代码来源:runtime.go


示例4: AppList

func AppList(configStore *config.Store, env string) error {

	envs := []string{env}

	if env == "" {
		var err error
		envs, err = configStore.ListEnvs()
		if err != nil {
			return err
		}
	}

	columns := []string{"NAME | ENV | VERSION | IMAGE ID | CONFIG | POOLS "}

	for _, env := range envs {

		appList, err := configStore.ListApps(env)
		if err != nil {
			return err
		}

		pools, err := configStore.ListPools(env)
		if err != nil {
			return err
		}

		for _, app := range appList {
			name := app.Name()
			versionDeployed := app.Version()
			versionID := app.VersionID()
			if len(versionID) > 12 {
				versionID = versionID[:12]
			}

			assignments := []string{}
			for _, pool := range pools {
				aa, err := configStore.ListAssignments(env, pool)
				if err != nil {
					return err
				}
				if utils.StringInSlice(app.Name(), aa) {
					assignments = append(assignments, pool)
				}
			}

			columns = append(columns, strings.Join([]string{
				name,
				env,
				versionDeployed,
				versionID,
				strconv.FormatInt(app.ID(), 10),
				strings.Join(assignments, ","),
			}, " | "))
		}
	}
	output := columnize.SimpleFormat(columns)
	fmt.Println(output)
	return nil
}
开发者ID:carriercomm,项目名称:galaxy,代码行数:59,代码来源:app.go


示例5: PoolExists

func (s *Store) PoolExists(env, pool string) (bool, error) {
	pools, err := s.ListPools(env)
	if err != nil {
		return false, err
	}

	return utils.StringInSlice(pool, pools), nil
}
开发者ID:sguzwf,项目名称:galaxy,代码行数:8,代码来源:store.go


示例6: ListAssignedPools

func (s *Store) ListAssignedPools(env, app string) ([]string, error) {
	pools, err := s.ListPools(env)
	if err != nil {
		return nil, err
	}

	assignments := []string{}
	for _, pool := range pools {
		apps, err := s.ListAssignments(env, pool)
		if err != nil {
			return nil, err
		}

		if utils.StringInSlice(app, apps) && !utils.StringInSlice(pool, assignments) {
			assignments = append(assignments, pool)
		}
	}
	return assignments, nil
}
开发者ID:sguzwf,项目名称:galaxy,代码行数:19,代码来源:store.go


示例7: RuntimePools

func (s *AppConfig) RuntimePools() []string {
	keys := s.runtimeVMap.Keys()
	pools := []string{}
	for _, k := range keys {
		pool := k[:strings.Index(k, "-")]
		if !utils.StringInSlice(pool, pools) {
			pools = append(pools, pool)
		}
	}
	return pools
}
开发者ID:sguzwf,项目名称:galaxy,代码行数:11,代码来源:app_config.go


示例8: appAssigned

func appAssigned(app string) (bool, error) {
	assignments, err := configStore.ListAssignments(env, pool)
	if err != nil {
		return false, err
	}

	if !utils.StringInSlice(app, assignments) {
		return false, nil
	}
	return true, nil
}
开发者ID:carriercomm,项目名称:galaxy,代码行数:11,代码来源:main.go


示例9: AssignApp

func (r *MemoryBackend) AssignApp(app, env, pool string) (bool, error) {
	if r.AssignAppFunc != nil {
		return r.AssignAppFunc(app, env, pool)
	}

	key := env + "/" + pool
	if !utils.StringInSlice(app, r.assignments[key]) {
		r.assignments[key] = append(r.assignments[key], app)
	}

	return true, nil
}
开发者ID:sguzwf,项目名称:galaxy,代码行数:12,代码来源:memory.go


示例10: UnassignApp

func (r *MemoryBackend) UnassignApp(app, env, pool string) (bool, error) {
	if r.UnassignAppFunc != nil {
		return r.UnassignAppFunc(app, env, pool)
	}

	key := env + "/" + pool
	if !utils.StringInSlice(app, r.assignments[key]) {
		return false, nil
	}
	r.assignments[key] = utils.RemoveStringInSlice(app, r.assignments[key])

	return true, nil
}
开发者ID:sguzwf,项目名称:galaxy,代码行数:13,代码来源:memory.go


示例11: GetImageByName

func (s *ServiceRuntime) GetImageByName(img string) (*docker.APIImages, error) {
	imgs, err := s.dockerClient.ListImages(docker.ListImagesOptions{All: true})
	if err != nil {
		panic(err)
	}

	for _, image := range imgs {
		if utils.StringInSlice(img, image.RepoTags) {
			return &image, nil
		}
	}
	return nil, nil

}
开发者ID:zombor,项目名称:galaxy,代码行数:14,代码来源:runtime.go


示例12: ListEnvs

func (r *RedisBackend) ListEnvs() ([]string, error) {
	envs := []string{}
	pools, err := r.Keys(path.Join("*", "pools", "*"))
	if err != nil {
		return nil, err
	}

	for _, pool := range pools {
		parts := strings.Split(pool, "/")
		if !utils.StringInSlice(parts[0], envs) {
			envs = append(envs, parts[0])
		}
	}
	return envs, nil
}
开发者ID:zombor,项目名称:galaxy,代码行数:15,代码来源:redis.go


示例13: ListEnvs

func (r *MemoryBackend) ListEnvs() ([]string, error) {
	if r.ListEnvsFunc != nil {
		return r.ListEnvsFunc()
	}

	p := []string{}
	for k, _ := range r.assignments {
		parts := strings.Split(k, "/")
		env := parts[0]
		if !utils.StringInSlice(env, p) {
			p = append(p, parts[0])
		}
	}
	return p, nil
}
开发者ID:sguzwf,项目名称:galaxy,代码行数:15,代码来源:memory.go


示例14: StopUnassigned

// Stop any running galaxy containers that are not assigned to us
// TODO: We call ManagedContainers a lot, repeatedly listing and inspecting all containers.
func (s *ServiceRuntime) StopUnassigned(env, pool string) error {
	containers, err := s.ManagedContainers()
	if err != nil {
		return err
	}

	for _, container := range containers {
		name := s.EnvFor(container)["GALAXY_APP"]

		pools, err := s.configStore.ListAssignedPools(env, name)
		if err != nil {
			log.Errorf("ERROR: Unable to list pool assignments for %s: %s", container.Name, err)
			continue
		}

		if len(pools) == 0 || !utils.StringInSlice(pool, pools) {
			log.Warnf("galaxy container %s not assigned to %s/%s", container.Name, env, pool)
			s.stopContainer(container)
		}
	}
	return nil
}
开发者ID:zombor,项目名称:galaxy,代码行数:24,代码来源:runtime.go


示例15: DeleteApp

func (s *Store) DeleteApp(app, env string) (bool, error) {

	pools, err := s.ListPools(env)
	if err != nil {
		return false, err
	}

	for _, pool := range pools {
		assignments, err := s.ListAssignments(env, pool)
		if err != nil {
			return false, err
		}
		if utils.StringInSlice(app, assignments) {
			return false, errors.New(fmt.Sprintf("app is assigned to pool %s", pool))
		}
	}

	svcCfg, err := s.Backend.GetApp(app, env)
	if err != nil {
		return false, err
	}

	if svcCfg == nil {
		return true, nil
	}

	deleted, err := s.Backend.DeleteApp(svcCfg, env)
	if !deleted || err != nil {
		return deleted, err
	}

	err = s.NotifyEnvChanged(env)
	if err != nil {
		return deleted, err
	}

	return true, nil
}
开发者ID:sguzwf,项目名称:galaxy,代码行数:38,代码来源:store.go


示例16: main


//.........这里部分代码省略.........
	case "pool":

		err := commander.ListPools(configStore, env)
		if err != nil {
			log.Fatal(err)
		}
		return

	case "pool:create":
		appFs := flag.NewFlagSet("pool:create", flag.ExitOnError)
		appFs.Usage = func() {
			println("Usage: commander -env <env> pool:create <pool>\n")
			println("    Create a pool in <env>\n")
			appFs.PrintDefaults()
		}
		appFs.Parse(flag.Args()[1:])

		ensureEnv()

		if pool == "" && appFs.NArg() > 0 {
			pool = appFs.Arg(0)
		} else {
			ensurePool()
		}

		err := commander.PoolCreate(configStore, env, pool)
		if err != nil {
			log.Fatalf("ERROR: Could not create pool: %s", err)
		}
		fmt.Println("created pool:", pool)
		return

	case "pool:delete":
		appFs := flag.NewFlagSet("pool:delete", flag.ExitOnError)
		appFs.Usage = func() {
			println("Usage: commander -env <env> pool:delete <pool>\n")
			println("    Delete a pool from <env>\n")
			appFs.PrintDefaults()
		}
		appFs.Parse(flag.Args()[1:])

		ensureEnv()

		if pool == "" && flag.NArg() > 1 {
			pool = flag.Arg(1)
		} else {
			ensurePool()
		}

		err := commander.PoolDelete(configStore, env, pool)
		if err != nil {
			log.Fatalf("ERROR: Could not delete pool: %s", err)
			return
		}

		fmt.Println("deleted pool:", pool)
		return

	default:
		fmt.Println("Unknown command")
		flag.Usage()
		os.Exit(1)
	}

	ensureEnv()
	ensurePool()

	log.Printf("Starting commander %s", buildVersion)
	log.Printf("env=%s pool=%s host-ip=%s registry=%s shuttle-addr=%s dns=%s cutoff=%ds",
		env, pool, hostIP, registryURL, shuttleAddr, dns, stopCutoff)

	defer func() {
		configStore.DeleteHost(env, pool, config.HostInfo{
			HostIP: hostIP,
		})
	}()

	for app, ch := range workerChans {
		if len(apps) == 0 || utils.StringInSlice(app, apps) {
			wg.Add(1)
			go restartContainers(app, ch)
			ch <- "deploy"
		}
	}

	if loop {
		wg.Add(1)
		go heartbeatHost()

		go discovery.Register(serviceRuntime, configStore, env, pool, hostIP, shuttleAddr)
		cancelChan := make(chan struct{})
		// do we need to cancel ever?

		restartChan := configStore.Watch(env, cancelChan)
		monitorService(restartChan)
	}

	// TODO: do we still need a WaitGroup?
	wg.Wait()
}
开发者ID:carriercomm,项目名称:galaxy,代码行数:101,代码来源:main.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang client.ServiceConfig类代码示例发布时间:2022-05-23
下一篇:
Golang utils.GalaxyEnv函数代码示例发布时间: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