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


Golang utils.StringInSlice函数代码示例

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


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


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