// fill the given reflect info with the field names mapped.
//
// fill will recurse into anonymous structs incrementing the index prefix
// so that untagged anonymous structs can be used as the source of truth.
344965
func (rm *reflectInfo) fill(t reflect.Type, indexPrefix []int) {
	// simple infinite recursion preventer: stop when we are >10 deep.
	if len(indexPrefix) > 10 {
		return
	}

	fillName := func(tag string, idx []int) {
		if _, ok := rm.names[tag]; !ok {
			rm.names[tag] = idx
		}
	}
	// these are anonymous structs to investigate (tail recursion)
	var toInvestigate [][]int
	for i := 0; i < t.NumField(); i++ {
		f := t.Field(i)
		tag := f.Tag.Get("avro")
		idx := append(append([]int{}, indexPrefix...), f.Index...)

		if f.Anonymous && tag == "" && f.Type.Kind() == reflect.Struct {
			toInvestigate = append(toInvestigate, idx)
		} else if strings.ToLower(f.Name[:1]) != f.Name[:1] {
			if tag != "" {
				fillName(tag, idx)
			} else {
				fillName(f.Name, idx)
				fillName(strings.ToLower(f.Name[:1])+f.Name[1:], idx)
			}
		}
	}
	for _, idx := range toInvestigate {
		// recurse into anonymous structs now that we handled the base ones.
		rm.fill(t.Field(idx[len(idx)-1]).Type, idx)
	}
}
168537
func Reflect(o interface{}, path string) interface{} {
	if path == "" {
		return o
	}

	parts := parsePointer(path)
	var rv interface{} = o

OUTER:
	for _, p := range parts {
		val := reflect.ValueOf(rv)
		if val.Kind() == reflect.Ptr {
			val = val.Elem()
		}

		if val.Kind() == reflect.Struct {
			typ := val.Type()
			for i := 0; i < typ.NumField(); i++ {
				sf := typ.Field(i)
				tag := sf.Tag.Get("json")
				name := parseJSONTagName(tag)
				if (name != "" && name == p) || sf.Name == p {
					rv = val.Field(i).Interface()
					continue OUTER
				}
			}
			// Found no matching field.
			return nil
		} else if val.Kind() == reflect.Map {
			// our pointer always gives us a string key
			// here we try to convert it into the correct type
			mapKey, canConvert := makeMapKeyFromString(val.Type().Key(), p)
			if canConvert {
				field := val.MapIndex(mapKey)
				if field.IsValid() {
					rv = field.Interface()
				} else {
					return nil
				}
			} else {
				return nil
			}
		} else if val.Kind() == reflect.Slice || val.Kind() == reflect.Array {
			i, err := strconv.Atoi(p)
			if err == nil && i < val.Len() {
				rv = val.Index(i).Interface()
			} else {
				return nil
			}
		} else {
			return nil
		}
	}

	return rv
}
93743
func fill(src, dest interface{}) (err error) {
	defer func() {
		if r := recover(); r != nil {
			d := reflect.TypeOf(dest)
			s := reflect.TypeOf(src)
			err = fmt.Errorf("the fill destination should be a pointer to a `%s`, but you used a `%s`", s, d)
		}
	}()

	reflect.ValueOf(dest).Elem().Set(reflect.ValueOf(src))

	return err
}
487478
func (v *Var) Parse(field reflect.StructField) error {
	v.SetName(field.Name)
	v.SetType(field.Type)
	v.SetKey(v.Name)

	tag := field.Tag.Get("env")

	if tag == "" {
		return nil
	}

	tagParams := strings.Split(tag, " ")
	for _, tagParam := range tagParams {
		var key, value string

		option := strings.Split(tagParam, "=")
		key = option[0]
		if len(option) > 1 {
			value = option[1]
		}

		switch key {
		case "key":
			// override the default key if one is specified
			v.SetKey(value)
		case "required":
			// val, _ := strconv.ParseBool(value)
			// if val != false {
			v.SetRequired(true)
			// }
		case "default":
			d, err := convert(v.Type, value)
			if err != nil {
				return err
			}
			v.SetDefault(d)
		case "options":
			in := strings.Split(value, ",")
			// var values []reflect.Value
			values := make([]reflect.Value, len(in))
			for k, val := range in {
				v1, err := convert(v.Type, val)
				if err != nil {
					return err
				}
				values[k] = v1
			}
			v.SetOptions(values)
		}
	}

	return nil
}
969282
func (ci *ConnInfo) fill(client *client, nc net.Conn, now time.Time) {
	ci.Cid = client.cid
	ci.Start = client.start
	ci.LastActivity = client.last
	ci.Uptime = myUptime(now.Sub(client.start))
	ci.Idle = myUptime(now.Sub(client.last))
	ci.RTT = client.getRTT()
	ci.OutMsgs = client.outMsgs
	ci.OutBytes = client.outBytes
	ci.NumSubs = uint32(len(client.subs))
	ci.Pending = int(client.out.pb)
	ci.Name = client.opts.Name
	ci.Lang = client.opts.Lang
	ci.Version = client.opts.Version
	// inMsgs and inBytes are updated outside of the client's lock, so
	// we need to use atomic here.
	ci.InMsgs = atomic.LoadInt64(&client.inMsgs)
	ci.InBytes = atomic.LoadInt64(&client.inBytes)

	// If the connection is gone, too bad, we won't set TLSVersion and TLSCipher.
	// Exclude clients that are still doing handshake so we don't block in
	// ConnectionState().
	if client.flags.isSet(handshakeComplete) && nc != nil {
		conn := nc.(*tls.Conn)
		cs := conn.ConnectionState()
		ci.TLSVersion = tlsVersion(cs.Version)
		ci.TLSCipher = tlsCipher(cs.CipherSuite)
	}

	if client.port != 0 {
		ci.Port = int(client.port)
		ci.IP = client.host
	}
}
748379
func (v *ViewPort) Fill(ch rune, style tcell.Style) {
	if v.v != nil {
		for y := 0; y < v.height; y++ {
			for x := 0; x < v.width; x++ {
				v.v.SetContent(x+v.physx, y+v.physy, ch, nil, style)
			}
		}
	}
}
159306
func (t *File) fill() error {
	t.fmu.Lock()
	_, err := io.Copy(t.ring, t.file)
	t.fmu.Unlock()
	switch err {
	case nil, io.ErrShortWrite, io.EOF:
		return nil
	default:
		return err
	}
}
847832
func fillJsonMap(json2ptr *map[string]*HashFieldDet, fx *[]Sexp, fl *[]reflect.StructField, embedPath []EmbedPath, tye reflect.Type, detOrder *[]*HashFieldDet) {
	var suffix string
	if len(embedPath) > 0 {
		suffix = fmt.Sprintf(" embed-path<%s>", GetEmbedPath(embedPath))
	}
	m := tye.NumField()
	for i := 0; i < m; i++ {
		fld := tye.Field(i)
		*fl = append(*fl, fld)
		*fx = append(*fx, &SexpStr{S: fld.Name + " " + fld.Type.String() + suffix})
		det := &HashFieldDet{
			FieldNum:     i,
			FieldType:    fld.Type,
			StructField:  fld,
			FieldName:    fld.Name,
			FieldJsonTag: fld.Name, // fallback. changed below if json tag available.
		}
		jsonTag := fld.Tag.Get("json")
		if jsonTag != "" {
			det.FieldJsonTag = jsonTag
			(*json2ptr)[jsonTag] = det
		} else {
			(*json2ptr)[fld.Name] = det
		}
		*detOrder = append(*detOrder, det)
		det.EmbedPath = append(embedPath,
			EmbedPath{ChildName: fld.Name, ChildFieldNum: i})
		if fld.Anonymous {
			// track how to get at embedded struct fields
			fillJsonMap(json2ptr, fx, fl, det.EmbedPath, fld.Type, detOrder)
		}
	}
}
903699
func FillLeft(s string, w int) string {
	return DefaultCondition.FillLeft(s, w)
}
1152499
func (s *Struct) FillMap(out map[string]interface{}) {
	if out == nil {
		return
	}

	fields := s.structFields()

	for _, field := range fields {
		name := field.Name
		val := s.value.FieldByName(name)
		isSubStruct := false
		var finalVal interface{}

		tagName, tagOpts := parseTag(field.Tag.Get(s.TagName))
		if tagName != "" {
			name = tagName
		}

		// if the value is a zero value and the field is marked as omitempty do
		// not include
		if tagOpts.Has("omitempty") {
			zero := reflect.Zero(val.Type()).Interface()
			current := val.Interface()

			if reflect.DeepEqual(current, zero) {
				continue
			}
		}

		if !tagOpts.Has("omitnested") {
			finalVal = s.nested(val)

			v := reflect.ValueOf(val.Interface())
			if v.Kind() == reflect.Ptr {
				v = v.Elem()
			}

			switch v.Kind() {
			case reflect.Map, reflect.Struct:
				isSubStruct = true
			}
		} else {
			finalVal = val.Interface()
		}

		if tagOpts.Has("string") {
			s, ok := val.Interface().(fmt.Stringer)
			if ok {
				out[name] = s.String()
			}
			continue
		}

		if isSubStruct && (tagOpts.Has("flatten")) {
			for k := range finalVal.(map[string]interface{}) {
				out[k] = finalVal.(map[string]interface{})[k]
			}
		} else {
			out[name] = finalVal
		}
	}
}
522410
func (c *Cluster) FillDefaults() error {
	// Topology support
	if c.Spec.Topology == nil {
		c.Spec.Topology = &TopologySpec{Masters: TopologyPublic, Nodes: TopologyPublic}
		c.Spec.Topology.DNS = &DNSSpec{Type: DNSTypePublic}
	}

	if c.Spec.Networking == nil {
		c.Spec.Networking = &NetworkingSpec{}
	}

	// TODO move this into networking.go :(
	if c.Spec.Networking.Classic != nil {
		// OK
	} else if c.Spec.Networking.Kubenet != nil {
		// OK
	} else if c.Spec.Networking.CNI != nil {
		// OK
	} else if c.Spec.Networking.External != nil {
		// OK
	} else if c.Spec.Networking.Kopeio != nil {
		// OK
	} else if c.Spec.Networking.Weave != nil {
		// OK
	} else if c.Spec.Networking.Flannel != nil {
		// OK
	} else if c.Spec.Networking.Calico != nil {
		// OK
	} else if c.Spec.Networking.Canal != nil {
		// OK
	} else if c.Spec.Networking.Kuberouter != nil {
		// OK
	} else if c.Spec.Networking.Romana != nil {
		// OK
	} else if c.Spec.Networking.AmazonVPC != nil {
		// OK
	} else if c.Spec.Networking.Cilium != nil {
		if c.Spec.Networking.Cilium.Version == "" {
			c.Spec.Networking.Cilium.Version = CiliumDefaultVersion
		}
		// OK
	} else if c.Spec.Networking.LyftVPC != nil {
		// OK
	} else {
		// No networking model selected; choose Kubenet
		c.Spec.Networking.Kubenet = &KubenetNetworkingSpec{}
	}

	if c.Spec.Channel == "" {
		c.Spec.Channel = DefaultChannel
	}

	if c.ObjectMeta.Name == "" {
		return fmt.Errorf("cluster Name not set in FillDefaults")
	}

	if c.Spec.MasterInternalName == "" {
		c.Spec.MasterInternalName = "api.internal." + c.ObjectMeta.Name
	}

	if c.Spec.MasterPublicName == "" {
		c.Spec.MasterPublicName = "api." + c.ObjectMeta.Name
	}

	return nil
}
917053
func (c *cache) create(t reflect.Type, parentAlias string) *structInfo {
	info := &structInfo{}
	var anonymousInfos []*structInfo
	for i := 0; i < t.NumField(); i++ {
		if f := c.createField(t.Field(i), parentAlias); f != nil {
			info.fields = append(info.fields, f)
			if ft := indirectType(f.typ); ft.Kind() == reflect.Struct && f.isAnonymous {
				anonymousInfos = append(anonymousInfos, c.create(ft, f.canonicalAlias))
			}
		}
	}
	for i, a := range anonymousInfos {
		others := []*structInfo{info}
		others = append(others, anonymousInfos[:i]...)
		others = append(others, anonymousInfos[i+1:]...)
		for _, f := range a.fields {
			if !containsAlias(others, f.alias) {
				info.fields = append(info.fields, f)
			}
		}
	}
	return info
}
1236606
func (m *Mapper) FieldMap(v reflect.Value) map[string]reflect.Value {
	v = reflect.Indirect(v)
	mustBe(v, reflect.Struct)

	r := map[string]reflect.Value{}
	tm := m.TypeMap(v.Type())
	for tagName, fi := range tm.Names {
		r[tagName] = FieldByIndexes(v, fi.Index)
	}
	return r
}
350654
func Fill(n int, input Input) []Input {
	a := make([]Input, n)
	for i := range a {
		a[i] = input
	}
	return a
}
485196
func FillNilSlices(data interface{}) error {
	s := reflect.ValueOf(data).Elem()
	t := s.Type()

	for i := 0; i < s.NumField(); i++ {
		f := s.Field(i)
		tag := t.Field(i).Tag

		v := tag.Get("default")
		if len(v) > 0 {
			switch f.Interface().(type) {
			case []string:
				if f.IsNil() {
					// Treat the default as a comma separated slice
					vs := strings.Split(v, ",")
					for i := range vs {
						vs[i] = strings.TrimSpace(vs[i])
					}

					rv := reflect.MakeSlice(reflect.TypeOf([]string{}), len(vs), len(vs))
					for i, v := range vs {
						rv.Index(i).SetString(v)
					}
					f.Set(rv)
				}
			}
		}
	}
	return nil
}
1110680
func Fill(element interface{}, node *Node) error {
	if element == nil || node == nil {
		return nil
	}

	if node.Kind == 0 {
		return fmt.Errorf("missing node type: %s", node.Name)
	}

	elem := reflect.ValueOf(element)
	if elem.Kind() == reflect.Struct {
		return fmt.Errorf("struct are not supported, use pointer instead")
	}

	return fill(elem.Elem(), node)
}
254834
func LoadStruct(obj interface{}, m map[string]interface{}, tagname string, ignoreUndefined bool) error {
	structValue := reflect.ValueOf(obj).Elem()
	for i := 0; i < structValue.NumField(); i++ {
		valueField := structValue.Field(i)
		structField := structValue.Type().Field(i)

		dest := structField.Tag.Get(tagname)
		if dest == "" {
			dest = structField.Name
		}
		if !valueField.IsValid() {
			return fmt.Errorf("No such field: %s in obj", structField.Name)
		}
		if !valueField.CanSet() {
			return fmt.Errorf("Cannot set %s field value", structField.Name)
		}
		importedValue, ok := m[dest]
		if !ok && !ignoreUndefined {
			return fmt.Errorf("input map[%v] is undefined", dest)
		}
		if importedValue == nil {
			if ignoreUndefined {
				continue
			}
			return fmt.Errorf("set value (named %v) can not be nil", dest)
		}
		newValue := reflect.ValueOf(importedValue)
		if structField.Type != newValue.Type() {
			invalidTypeError := errors.New("Provided value type didn't match obj field type")
			return invalidTypeError
		}
		valueField.Set(newValue)
	}
	return nil
}