// Return a merged environment var which is split into multiple
// vars. This is useful when the system has a size limit on
// environment variables.
512175
func JoinEnvNumbered(prefix, delimiter string, startInt uint8, includeBase bool) string {
	vals := []string{}
	if includeBase {
		val := os.Getenv(prefix)
		if len(val) > 0 {
			vals = append(vals, val)
		}
	}
	i := startInt
	for {
		val := os.Getenv(fmt.Sprintf("%s_%d", prefix, i))
		if len(val) > 0 {
			vals = append(vals, val)
		} else {
			break
		}
		i++
	}
	return strings.Join(vals, delimiter)
}
484668
func Convert_core_EnvVar_To_v1_EnvVar(in *core.EnvVar, out *v1.EnvVar, s conversion.Scope) error {
	return autoConvert_core_EnvVar_To_v1_EnvVar(in, out, s)
}
1098019
func (c *ServerContext) GetEnv(key string) (string, bool) {
	val, ok := c.env[key]
	return val, ok
}
348658
func (ctx *limitedContext) SetEnvVars(vars map[string]string) {
	if ctx.env == nil {
		ctx.env = vars
		return
	}
	for key, val := range vars {
		ctx.env[key] = val
	}
}
707569
func Getenv(ctx context.Context, key string) string {
	val, _ := LookupEnv(ctx, key)
	return val
}
1334638
func (t *Template) WithEnvS(envs []string) *Template {
	var result = map[string]string{}
	for _, env := range envs {
		var parts = strings.SplitN(env, "=", 2)
		result[parts[0]] = parts[1]
	}
	return t.WithEnv(result)
}
1364401
func MergeEnvironmentWith(env *envmanModels.EnvironmentItemModel, otherEnv envmanModels.EnvironmentItemModel) error {
	// merge key-value
	key, _, err := env.GetKeyValuePair()
	if err != nil {
		return err
	}

	otherKey, otherValue, err := otherEnv.GetKeyValuePair()
	if err != nil {
		return err
	}

	if otherKey != key {
		return errors.New("Env keys are diferent")
	}

	(*env)[key] = otherValue

	//merge options
	options, err := env.GetOptions()
	if err != nil {
		return err
	}

	otherOptions, err := otherEnv.GetOptions()
	if err != nil {
		return err
	}

	if otherOptions.IsSensitive != nil {
		options.IsSensitive = pointers.NewBoolPtr(*otherOptions.IsSensitive)
	}
	if otherOptions.IsExpand != nil {
		options.IsExpand = pointers.NewBoolPtr(*otherOptions.IsExpand)
	}
	if otherOptions.SkipIfEmpty != nil {
		options.SkipIfEmpty = pointers.NewBoolPtr(*otherOptions.SkipIfEmpty)
	}

	if otherOptions.Title != nil {
		options.Title = pointers.NewStringPtr(*otherOptions.Title)
	}
	if otherOptions.Description != nil {
		options.Description = pointers.NewStringPtr(*otherOptions.Description)
	}
	if otherOptions.Summary != nil {
		options.Summary = pointers.NewStringPtr(*otherOptions.Summary)
	}
	if otherOptions.Category != nil {
		options.Category = pointers.NewStringPtr(*otherOptions.Category)
	}
	if len(otherOptions.ValueOptions) > 0 {
		options.ValueOptions = otherOptions.ValueOptions
	}
	if otherOptions.IsRequired != nil {
		options.IsRequired = pointers.NewBoolPtr(*otherOptions.IsRequired)
	}
	if otherOptions.IsDontChangeValue != nil {
		options.IsDontChangeValue = pointers.NewBoolPtr(*otherOptions.IsDontChangeValue)
	}
	if otherOptions.IsTemplate != nil {
		options.IsTemplate = pointers.NewBoolPtr(*otherOptions.IsTemplate)
	}
	(*env)[envmanModels.OptionsKey] = options
	return nil
}
613457
func buildDockerEnvironmentVars(env map[string]string) []string {
	var list []string
	for k, v := range env {
		list = append(list, []string{"-e", fmt.Sprintf("%s=%s", k, v)}...)
	}

	return list
}
990096
func NewEnvVars(assert Assertion) *EnvVars {
	ev := &EnvVars{
		assert: assert,
		vars:   make(map[string]string),
	}
	return ev
}
768175
func getProxyEnvVars() []v1.EnvVar {
	envs := []v1.EnvVar{}
	for _, env := range os.Environ() {
		pos := strings.Index(env, "=")
		if pos == -1 {
			// malformed environment variable, skip it.
			continue
		}
		name := env[:pos]
		value := env[pos+1:]
		if strings.HasSuffix(strings.ToLower(name), "_proxy") && value != "" {
			envVar := v1.EnvVar{Name: name, Value: value}
			envs = append(envs, envVar)
		}
	}
	return envs
}
204640
func Env(m map[string]string) (env []string) {
	for k, v := range m {
		env = append(env, fmt.Sprintf("%s=%s", k, v))
	}
	return
}
232215
func joinEnv(env map[string]string) []string {
	vals := make([]string, 0, len(env))
	for k, v := range env {
		vals = append(vals, k+"="+v)
	}
	return vals
}
990905
func GetenvWithDefault(envKey, defValue string) string {
	retVal := os.Getenv(envKey)
	if retVal == "" {
		return defValue
	}
	return retVal
}
33636
func LoadEnvVariables() {
	if os.Getenv("GONI_PROMODE") == "true" || EnableProductionMode {
		gin.SetMode(gin.ReleaseMode)
	}

	if os.Getenv("GONI_REST") == "false" {
		EnableRestAPI = false
	}

	if os.Getenv("GONI_STREAM") == "false" {
		EnableStreamAPI = false
	}
}
706058
func (c *config) flattenEnvVars(
	prefix string, keys map[string]interface{}, envVars map[string]string) {

	for k, v := range keys {

		var kk string
		if prefix == "" {
			kk = k
		} else {
			kk = fmt.Sprintf("%s.%s", prefix, k)
		}
		ek := strings.ToUpper(strings.Replace(kk, ".", "_", -1))

		if LogFlattenEnvVars {
			log.WithFields(log.Fields{
				"key":   kk,
				"value": v,
			}).Debug("flattening env vars")
		}

		switch vt := v.(type) {
		case string:
			envVars[ek] = vt
		case []interface{}:
			var vArr []string
			for _, iv := range vt {
				vArr = append(vArr, iv.(string))
			}
			envVars[ek] = strings.Join(vArr, " ")
		case map[string]interface{}:
			c.flattenEnvVars(kk, vt, envVars)
		case bool:
			envVars[ek] = fmt.Sprintf("%v", vt)
		case int, int32, int64:
			envVars[ek] = fmt.Sprintf("%v", vt)
		}
	}
	return
}
610596
func (c *Gcd) AddEnvironmentVars(vars []string) {
	c.env = append(c.env, vars...)
}
1338826
func LookupEnv(ctx context.Context, key string) subcommands.EnvVar {
	e, _ := ctx.Value(&envKey).(subcommands.Env)
	return e[key]
}