// expandDests returns a list of destinations that have been expanded from the
// vserver configuration and a given service.
550455
func (v *vserver) expandDests(svc *service) map[destinationKey]*destination {
	dsts := make(map[destinationKey]*destination, len(v.config.Backends))
	for _, backend := range v.config.Backends {
		var ip net.IP
		switch svc.af {
		case seesaw.IPv4:
			ip = backend.Host.IPv4Addr
		case seesaw.IPv6:
			ip = backend.Host.IPv6Addr
		}
		if ip == nil {
			continue
		}
		dst := &destination{
			destinationKey: newDestinationKey(ip),
			service:        svc,
			backend:        backend,
			weight:         backend.Weight,
		}
		dst.ipvsDst = dst.ipvsDestination()
		dst.stats = &seesaw.DestinationStats{}
		dsts[dst.destinationKey] = dst
	}
	return dsts
}
1130009
func (c *FleetClient) expandTargets(targets []string) (expandedTargets []string, err error) {
	for _, t := range targets {
		// ensure unit name starts with "deis-"
		if !strings.HasPrefix(t, "deis-") {
			t = "deis-" + t
		}
		if strings.HasSuffix(t, "@*") {
			var targets []string
			targets, err = c.Units(strings.TrimSuffix(t, "@*"))
			if err != nil {
				return
			}
			expandedTargets = append(expandedTargets, targets...)
		} else {
			expandedTargets = append(expandedTargets, t)
		}

	}
	return
}
782123
func Expand(u *url.URL, expansions map[string]string) {
	expanded, err := uritemplates.Expand(u.Path, expansions)
	if err == nil {
		u.Path = expanded
		SetOpaque(u)
	}
}
876910
func expandEcsLoadBalancers(configured []interface{}) []*ecs.LoadBalancer {
	loadBalancers := make([]*ecs.LoadBalancer, 0, len(configured))

	// Loop over our configured load balancers and create
	// an array of aws-sdk-go compatible objects
	for _, lRaw := range configured {
		data := lRaw.(map[string]interface{})

		l := &ecs.LoadBalancer{
			ContainerName: aws.String(data["container_name"].(string)),
			ContainerPort: aws.Int64(int64(data["container_port"].(int))),
		}

		if v, ok := data["elb_name"]; ok && v.(string) != "" {
			l.LoadBalancerName = aws.String(v.(string))
		}
		if v, ok := data["target_group_arn"]; ok && v.(string) != "" {
			l.TargetGroupArn = aws.String(v.(string))
		}

		loadBalancers = append(loadBalancers, l)
	}

	return loadBalancers
}
1197520
func (s *IndicesOpenService) ExpandWildcards(expandWildcards string) *IndicesOpenService {
	s.expandWildcards = expandWildcards
	return s
}
1172379
func ExpandStrict(s string, fns ...KeyFunc) (string, error) {
	unmatched := []string{}
	result := os.Expand(s, func(key string) string {
		for _, fn := range fns {
			val, ok := fn(key)
			if !ok {
				continue
			}
			return val
		}
		unmatched = append(unmatched, key)
		return ""
	})

	switch len(unmatched) {
	case 0:
		return result, nil
	case 1:
		return "", fmt.Errorf("the key %q in %q is not recognized", unmatched[0], s)
	default:
		return "", fmt.Errorf("multiple keys in %q were not recognized: %s", s, strings.Join(unmatched, ", "))
	}
}
1110615
func ExpandEnvItems(toExpand []models.EnvironmentItemModel, externalEnvs []string) (map[string]string, error) {
	externalEnvMap, err := envListToMap(externalEnvs)
	if err != nil {
		return nil, err
	}

	mapper := func(key string) string {
		return externalEnvMap[key]
	}

	expanded := map[string]string{}
	for _, env := range toExpand {
		key, value, err := env.GetKeyValuePair()
		if err != nil {
			return nil, err
		}

		opts, err := env.GetOptions()
		if err != nil {
			return nil, err
		}

		if opts.SkipIfEmpty != nil && *opts.SkipIfEmpty && value == "" {
			continue
		}

		if opts.IsExpand != nil && *opts.IsExpand {
			value = os.Expand(value, mapper)
		}

		externalEnvMap[key] = value
		expanded[key] = value
	}

	return expanded, nil
}
339635
func expandFloat64Map(m map[string]interface{}) map[string]*float64 {
	float64Map := make(map[string]*float64, len(m))
	for k, v := range m {
		float64Map[k] = aws.Float64(v.(float64))
	}
	return float64Map
}
1158132
func (s *IndicesPutMappingService) ExpandWildcards(expandWildcards string) *IndicesPutMappingService {
	s.expandWildcards = expandWildcards
	return s
}
101629
func expandDirectories(dirs []string) ([]string, error) {
	const recursiveMarker = "/..."
	resultSet := make([]string, 0)
	for _, dir := range dirs {
		if strings.HasSuffix(dir, recursiveMarker) {
			err := filepath.Walk(strings.TrimSuffix(dir, recursiveMarker), func(path string, info os.FileInfo, err error) error {
				if info.IsDir() {
					resultSet = append(resultSet, path)
				}
				return nil
			})
			if err != nil {
				return nil, err
			}
		} else {
			info, err := os.Stat(dir)
			if err != nil {
				return nil, err
			}
			if !info.IsDir() {
				return nil, fmt.Errorf("%q is not a directory", dir)
			}
			resultSet = append(resultSet, dir)
		}
	}
	if len(resultSet) == 0 {
		// treat an empty list as a search in the current directory (think "ls")
		return []string{"."}, nil
	}

	return resultSet, nil
}
315190
func (tp Platform) Expander() Expander {
	return Expander{
		"os":       tp.OS,
		"arch":     tp.Arch,
		"platform": tp.String(),
	}
}
288453
func (v *vserver) expandChecks() map[checkKey]*check {
	checks := make(map[checkKey]*check)
	for _, svc := range v.services {
		for _, dest := range svc.dests {
			dest.checks = make([]*check, 0)
			if !dest.backend.Enabled {
				continue
			}
			for _, hc := range v.config.Healthchecks {
				// vserver-level healthchecks
				key := newCheckKey(svc.ip, dest.ip, 0, 0, hc)
				c := checks[key]
				if c == nil {
					c = newCheck(key, v, hc)
					checks[key] = c
				}
				dest.checks = append(dest.checks, c)
				c.dests = append(c.dests, dest)
			}

			// ventry-level healthchecks
			if v.config.UseFWM {
				for _, ve := range svc.vserver.config.Entries {
					for _, hc := range ve.Healthchecks {
						key := newCheckKey(svc.ip, dest.ip, ve.Port, ve.Proto, hc)
						c := newCheck(key, v, hc)
						checks[key] = c
						dest.checks = append(dest.checks, c)
						c.dests = append(c.dests, dest)
					}
				}
			} else {
				for _, hc := range svc.ventry.Healthchecks {
					key := newCheckKey(svc.ip, dest.ip, svc.port, svc.proto, hc)
					c := newCheck(key, v, hc)
					checks[key] = c
					dest.checks = append(dest.checks, c)
					c.dests = append(c.dests, dest)
				}
			}
		}
	}
	return checks
}
377454
func (b LocationBounds) Expand(loc Location) LocationBounds {
	if b == (LocationBounds{}) {
		return LocationBounds{
			North: loc.Latitude,
			South: loc.Latitude,
			West:  loc.Longitude,
			East:  loc.Longitude,
		}
	}
	nb := LocationBounds{
		North: b.North,
		South: b.South,
		West:  b.West,
		East:  b.East,
	}
	if loc.Latitude > nb.North {
		nb.North = loc.Latitude
	} else if loc.Latitude < nb.South {
		nb.South = loc.Latitude
	}
	if nb.Contains(loc) {
		return nb
	}
	center := nb.center()
	dToCenter := center.Longitude - loc.Longitude
	if math.Abs(dToCenter) <= 180 {
		if dToCenter > 0 {
			// expand Westwards
			nb.West = loc.Longitude
		} else {
			// expand Eastwards
			nb.East = loc.Longitude
		}
		return nb
	}
	if dToCenter > 0 {
		// expand Eastwards
		nb.East = loc.Longitude
	} else {
		// expand Westwards
		nb.West = loc.Longitude
	}
	return nb
}
1321459
func (s *PutMappingService) ExpandWildcards(expandWildcards string) *PutMappingService {
	s.expandWildcards = expandWildcards
	return s
}
1292605
func expand(match map[string]string, s string) string {
	for k, v := range match {
		s = strings.Replace(s, "{"+k+"}", v, -1)
	}
	return s
}
930437
func expandResourceShortcut(resource string) string {
	shortForms := map[string]string{
		// Please keep this alphabetized
		"cs":     "componentstatuses",
		"ev":     "events",
		"ep":     "endpoints",
		"hpa":    "horizontalpodautoscalers",
		"limits": "limitranges",
		"no":     "nodes",
		"ns":     "namespaces",
		"po":     "pods",
		"pv":     "persistentvolumes",
		"pvc":    "persistentvolumeclaims",
		"quota":  "resourcequotas",
		"rc":     "replicationcontrollers",
		"ds":     "daemonsets",
		"svc":    "services",
		"ing":    "ingresses",
	}
	if expanded, ok := shortForms[resource]; ok {
		return expanded
	}
	return resource
}
904705
func (s *FlushService) ExpandWildcards(expandWildcards string) *FlushService {
	s.expandWildcards = expandWildcards
	return s
}