// Create a simple middleware that merges a map into c.Env
15818
func EnvAdd(m map[string]interface{}) web.MiddlewareType {
	return func(c *web.C, h http.Handler) http.Handler {
		return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
			for k, v := range m {
				c.Env[k] = v
			}
			h.ServeHTTP(rw, r)
		})
	}
}
461360
func Merge(mapA map[string]interface{}, mapB map[string]interface{}) map[string]interface{} {
	for k, v := range mapA {
		mapB[k] = v
	}

	return mapB
}
788185
func Merge(c1, c2 *Config) (*Config, error) {
	c := new(Config)

	// Merge unknown keys
	unknowns := make(map[string]struct{})
	for _, k := range c1.unknownKeys {
		_, present := unknowns[k]
		if !present {
			unknowns[k] = struct{}{}
			c.unknownKeys = append(c.unknownKeys, k)
		}
	}
	for _, k := range c2.unknownKeys {
		_, present := unknowns[k]
		if !present {
			unknowns[k] = struct{}{}
			c.unknownKeys = append(c.unknownKeys, k)
		}
	}

	// Merge Atlas configuration. This is a dumb one overrides the other
	// sort of merge.
	c.Atlas = c1.Atlas
	if c2.Atlas != nil {
		c.Atlas = c2.Atlas
	}

	// Merge the Terraform configuration
	if c1.Terraform != nil {
		c.Terraform = c1.Terraform
		if c2.Terraform != nil {
			c.Terraform.Merge(c2.Terraform)
		}
	} else {
		c.Terraform = c2.Terraform
	}

	// NOTE: Everything below is pretty gross. Due to the lack of generics
	// in Go, there is some hoop-jumping involved to make this merging a
	// little more test-friendly and less repetitive. Ironically, making it
	// less repetitive involves being a little repetitive, but I prefer to
	// be repetitive with things that are less error prone than things that
	// are more error prone (more logic). Type conversions to an interface
	// are pretty low-error.

	var m1, m2, mresult []merger

	// Modules
	m1 = make([]merger, 0, len(c1.Modules))
	m2 = make([]merger, 0, len(c2.Modules))
	for _, v := range c1.Modules {
		m1 = append(m1, v)
	}
	for _, v := range c2.Modules {
		m2 = append(m2, v)
	}
	mresult = mergeSlice(m1, m2)
	if len(mresult) > 0 {
		c.Modules = make([]*Module, len(mresult))
		for i, v := range mresult {
			c.Modules[i] = v.(*Module)
		}
	}

	// Outputs
	m1 = make([]merger, 0, len(c1.Outputs))
	m2 = make([]merger, 0, len(c2.Outputs))
	for _, v := range c1.Outputs {
		m1 = append(m1, v)
	}
	for _, v := range c2.Outputs {
		m2 = append(m2, v)
	}
	mresult = mergeSlice(m1, m2)
	if len(mresult) > 0 {
		c.Outputs = make([]*Output, len(mresult))
		for i, v := range mresult {
			c.Outputs[i] = v.(*Output)
		}
	}

	// Provider Configs
	m1 = make([]merger, 0, len(c1.ProviderConfigs))
	m2 = make([]merger, 0, len(c2.ProviderConfigs))
	for _, v := range c1.ProviderConfigs {
		m1 = append(m1, v)
	}
	for _, v := range c2.ProviderConfigs {
		m2 = append(m2, v)
	}
	mresult = mergeSlice(m1, m2)
	if len(mresult) > 0 {
		c.ProviderConfigs = make([]*ProviderConfig, len(mresult))
		for i, v := range mresult {
			c.ProviderConfigs[i] = v.(*ProviderConfig)
		}
	}

	// Resources
	m1 = make([]merger, 0, len(c1.Resources))
	m2 = make([]merger, 0, len(c2.Resources))
	for _, v := range c1.Resources {
		m1 = append(m1, v)
	}
	for _, v := range c2.Resources {
		m2 = append(m2, v)
	}
	mresult = mergeSlice(m1, m2)
	if len(mresult) > 0 {
		c.Resources = make([]*Resource, len(mresult))
		for i, v := range mresult {
			c.Resources[i] = v.(*Resource)
		}
	}

	// Variables
	m1 = make([]merger, 0, len(c1.Variables))
	m2 = make([]merger, 0, len(c2.Variables))
	for _, v := range c1.Variables {
		m1 = append(m1, v)
	}
	for _, v := range c2.Variables {
		m2 = append(m2, v)
	}
	mresult = mergeSlice(m1, m2)
	if len(mresult) > 0 {
		c.Variables = make([]*Variable, len(mresult))
		for i, v := range mresult {
			c.Variables[i] = v.(*Variable)
		}
	}

	// Local Values
	// These are simpler than the other config elements because they are just
	// flat values and so no deep merging is required.
	if localsCount := len(c1.Locals) + len(c2.Locals); localsCount != 0 {
		// Explicit length check above because we want c.Locals to remain
		// nil if the result would be empty.
		c.Locals = make([]*Local, 0, len(c1.Locals)+len(c2.Locals))
		c.Locals = append(c.Locals, c1.Locals...)
		c.Locals = append(c.Locals, c2.Locals...)
	}

	return c, nil
}
701183
func mergeEnvs(appEnv *types.Environment, env []string, override bool) {
	for _, ev := range env {
		pair := strings.SplitN(ev, "=", 2)
		if _, exists := appEnv.Get(pair[0]); override || !exists {
			appEnv.Set(pair[0], pair[1])
		}
	}
}
1004199
func merge(maps ...map[string]string) map[string]string {
	var output map[string]string = nil
	for _, m := range maps {
		if m != nil && output == nil {
			output = map[string]string{}
		}
		for k, v := range m {
			output[k] = v
		}
	}
	return output
}
1223469
func (c *Command) AddEnvs(envs ...string) *Command {
	c.envs = append(c.envs, envs...)
	return c
}
1330904
func main() {
	env, err := plugins.NewEnvironment()
	env.RespondAndExitIfError(err)

	packageName, err := resolvePackageName(env.Request.OutputPath)
	env.RespondAndExitIfError(err)

	// Use the name used to run the plugin to decide which files to generate.
	var files []string
	switch {
	case strings.Contains(env.Invocation, "gnostic-go-client"):
		files = []string{"client.go", "types.go", "constants.go"}
	case strings.Contains(env.Invocation, "gnostic-go-server"):
		files = []string{"server.go", "provider.go", "types.go", "constants.go"}
	default:
		files = []string{"client.go", "server.go", "provider.go", "types.go", "constants.go"}
	}

	for _, model := range env.Request.Models {
		switch model.TypeUrl {
		case "surface.v1.Model":
			surfaceModel := &surface.Model{}
			err = proto.Unmarshal(model.Value, surfaceModel)
			if err == nil {
				// Customize the code surface model for Go
				NewGoLanguageModel().Prepare(surfaceModel)

				modelJSON, _ := json.MarshalIndent(surfaceModel, "", "  ")
				modelFile := &plugins.File{Name: "model.json", Data: modelJSON}
				env.Response.Files = append(env.Response.Files, modelFile)

				// Create the renderer.
				renderer, err := NewServiceRenderer(surfaceModel)
				renderer.Package = packageName
				env.RespondAndExitIfError(err)

				// Run the renderer to generate files and add them to the response object.
				err = renderer.Render(env.Response, files)
				env.RespondAndExitIfError(err)

				// Return with success.
				env.RespondAndExit()
			}
		}
	}
	err = errors.New("No generated code surface model is available.")
	env.RespondAndExitIfError(err)
}
358458
func (c *context) Env() map[string]string {
	env := make(map[string]string)
	for _, i := range os.Environ() {
		sep := strings.Index(i, "=")
		env[i[0:sep]] = i[sep+1:]
	}
	return env
}
756875
func mergeEnvWin(current, newValues map[string]string) map[string]string {
	uppers := make(map[string]string, len(current))
	news := map[string]string{}
	for k, v := range current {
		uppers[strings.ToUpper(k)] = v
	}

	for k, v := range newValues {
		up := strings.ToUpper(k)
		if _, ok := uppers[up]; ok {
			uppers[up] = v
		} else {
			news[k] = v
		}
	}

	for k := range current {
		current[k] = uppers[strings.ToUpper(k)]
	}
	for k, v := range news {
		current[k] = v
	}
	return current
}
684052
func (m *ServeMux) Middleware(f MiddlewareFunc) {
	m.middlewares = append(m.middlewares, f)
}
1170001
func environment(vars Vars) map[string]string {
	env := make(map[string]string)

	for k, v := range vars {
		env[string(k)] = string(*v)
	}

	return env
}
1105181
func WriteEnvMapToFile(pth string, envs []models.EnvironmentItemModel) error {
	if pth == "" {
		return errors.New("No path provided")
	}

	envYML, err := generateFormattedYMLForEnvModels(envs)
	if err != nil {
		return err
	}
	bytes, err := yaml.Marshal(envYML)
	if err != nil {
		return err
	}
	return fileutil.WriteBytesToFile(pth, bytes)
}
760221
func mergeEnv(envVars []api.EnvVar, podPresets []*settingsv1alpha1.PodPreset) ([]api.EnvVar, error) {
	origEnv := map[string]api.EnvVar{}
	for _, v := range envVars {
		origEnv[v.Name] = v
	}

	mergedEnv := make([]api.EnvVar, len(envVars))
	copy(mergedEnv, envVars)

	var errs []error

	for _, pp := range podPresets {
		for _, v := range pp.Spec.Env {
			internalEnv := api.EnvVar{}
			if err := apiscorev1.Convert_v1_EnvVar_To_core_EnvVar(&v, &internalEnv, nil); err != nil {
				return nil, err
			}

			found, ok := origEnv[v.Name]
			if !ok {
				// if we don't already have it append it and continue
				origEnv[v.Name] = internalEnv
				mergedEnv = append(mergedEnv, internalEnv)
				continue
			}

			// make sure they are identical or throw an error
			if !reflect.DeepEqual(found, internalEnv) {
				errs = append(errs, fmt.Errorf("merging env for %s has a conflict on %s: \n%#v\ndoes not match\n%#v\n in container", pp.GetName(), v.Name, v, found))
			}
		}
	}

	err := utilerrors.NewAggregate(errs)
	if err != nil {
		return nil, err
	}

	return mergedEnv, err
}
1279593
func dotEnv(in string) (interface{}, error) {
	env, err := godotenv.Unmarshal(in)
	if err != nil {
		return nil, err
	}
	out := make(map[string]interface{})
	for k, v := range env {
		out[k] = v
	}
	return out, nil
}
987305
func Create(fname string, size int) (*Env, error) {
	f, err := os.Create(fname)
	if err != nil {
		return nil, err
	}
	defer f.Close()

	env := &Env{
		fname: fname,
		size:  size,
		data:  make(map[string]string),
	}

	return env, nil
}
725593
func (c *Config) EnvVars() map[string]string {
	vars := make(map[string]string, len(c.Params))
	for _, p := range c.Params {
		k, v := p.EnvVars()
		vars[k] = v
	}
	return vars
}
762796
func EnvVarsToMap(envs []EnvVar) map[string]string {
	result := map[string]string{}
	for _, env := range envs {
		result[env.Name] = env.Value
	}
	return result
}