// Returns the index in the struct for the named field, as well as the parsed tag properties.
507320
func structFieldByName(st reflect.Type, name string) (int, *Properties, bool) {
	sprops := GetProperties(st)
	i, ok := sprops.decoderOrigNames[name]
	if ok {
		return i, sprops.Prop[i], true
	}
	return -1, nil, false
}
900142
func (self *Collection) GetField(name string) (Field, bool) {
	if name == self.GetIdentityFieldName() {
		return Field{
			Name:     name,
			Type:     self.IdentityFieldType,
			Index:    self.IdentityFieldIndex,
			Identity: true,
			Key:      true,
			Required: true,
		}, true
	} else {
		for _, field := range self.Fields {
			if field.Name == name {
				return field, true
			}
		}
	}

	return Field{}, false
}
1304037
func TaggedSearch(client ClientInterface, tag string, params url.Values) (*SearchResults, error) {
	params.Set("tag", tag)
	response, err := client.GetWithParams("/tagged", params)
	if err != nil {
		return nil, err
	}
	result := struct {
		Response []MiniPost `json:"response"`
	}{}
	if err = json.Unmarshal(response.body, &result); err != nil {
		return nil, err
	}
	minis := result.Response
	full := SearchResults{
		Posts:  makePostsFromMinis(minis, client),
		client: client,
		params: params,
	}
	if err = json.Unmarshal(response.body, &full); err != nil {
		return nil, err
	}
	return &full, nil
}
441611
func getFields(s interface{}) (ret []reflect.StructField) {
	val := reflect.Indirect(reflect.ValueOf(s))
	// addIf adds filedType to ret if is not marked as `sql:"-"`
	addIf := func(fieldType reflect.StructField) {
		tag := strings.ToLower(fieldType.Tag.Get("sql"))
		tagValue := strings.Split(tag, ",")
		sort.Strings(tagValue)
		idx := sort.SearchStrings(tagValue, "-")
		if idx == len(tagValue) || tagValue[idx] != "-" {
			ret = append(ret, fieldType)
		}
	}
	for i := 0; i < val.NumField(); i++ {
		fieldValue := val.Field(i)
		fieldType := val.Type().Field(i)
		// if it's exported
		if fieldType.PkgPath == "" {
			// Handle embedded anoymous struct
			switch fieldValue.Kind() {
			case reflect.Struct:
				// if it's anonymous, embed its fields in the query
				if fieldType.Anonymous {
					ret = append(ret, getFields(fieldValue.Interface())...)
				} else { // use its name only (to work with structs like time.Time)
					addIf(fieldType)
				}
			default:
				addIf(fieldType)
			}
		}
	}

	return
}
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
}
857350
func (f *IndexFile) TagValueElem(name, key, value []byte) TagValueElem {
	tblk, ok := f.tblks[string(name)]
	if !ok {
		return nil
	}
	return tblk.TagValueElem(key, value)
}
1001128
func (s *Struct) structFields() []reflect.StructField {
	t := s.value.Type()

	var f []reflect.StructField

	for i := 0; i < t.NumField(); i++ {
		field := t.Field(i)
		// we can't access the value of unexported fields
		if field.PkgPath != "" {
			continue
		}

		// don't check if it's omitted
		if tag := field.Tag.Get(s.TagName); tag == "-" {
			continue
		}

		f = append(f, field)
	}

	return f
}
1279934
func (tag PluginStructTag) GetStringArray() []string {
	tagValue, tagSet := reflect.StructTag(tag).Lookup(PluginStructTagDefault)
	if !tagSet {
		return []string{}
	}
	return strings.Split(tagValue, ",")
}
879001
func (fs *UnstructAdapter) GetFieldValue(path string) (string, error) {
	fields, err := parseFields(path)
	if err != nil {
		return "", err
	}
	s, found, err := unstructured.NestedString(
		fs.UnstructuredContent(), fields...)
	if found || err != nil {
		return s, err
	}
	return "", fmt.Errorf("no field named '%s'", path)
}
325612
func getErrorFieldName(f *reflect.StructField) string {
	if tag := f.Tag.Get(ErrorTag); tag != "" {
		if cps := strings.SplitN(tag, ",", 2); cps[0] != "" {
			return cps[0]
		}
	}
	return f.Name
}
1001034
func (p *gc_parser) parse_field() *ast.Field {
	var tag string
	name, _ := p.parse_name()
	typ := p.parse_type()
	if p.tok == scanner.String {
		tag = p.expect(scanner.String)
	}

	var names []*ast.Ident
	if name != "?" {
		names = []*ast.Ident{ast.NewIdent(name)}
	}

	return &ast.Field{
		Names: names,
		Type:  typ,
		Tag:   &ast.BasicLit{Kind: token.STRING, Value: tag},
	}
}
971904
func (p *IndexFiles) TagKeyIterator(name []byte) (TagKeyIterator, error) {
	a := make([]TagKeyIterator, 0, len(*p))
	for _, f := range *p {
		itr := f.TagKeyIterator(name)
		if itr == nil {
			continue
		}
		a = append(a, itr)
	}
	return MergeTagKeyIterators(a...), nil
}
656276
func GetFieldTag(obj interface{}, fieldName, tagKey string) (string, error) {
	field, err := getInnerFieldType(obj, fieldName)
	if err != nil {
		return "", err
	}

	if !isExportableField(field) {
		return "", errors.New("Cannot GetFieldTag on a non-exported struct field")
	}

	return field.Tag.Get(tagKey), nil
}
764071
func (e *Encoder) getFieldName(field reflect.StructField) string {
	if e.useTags {
		name := field.Tag.Get(e.tag)
		// skip columns tagged with -
		if name == "-" {
			return ""
		}
		if name != "" {
			return name
		}
	}
	return field.Name

}
1022834
func getFields(dstType reflect.Type) (*structData, error) {
	fieldsCacheMutex.Lock()
	defer fieldsCacheMutex.Unlock()

	if result, present := fieldsCache[dstType]; present {
		return result, nil
	}

	// make sure dst is a non-nil pointer to a struct
	if dstType.Kind() != reflect.Ptr {
		return nil, fmt.Errorf("meddler called with non-pointer destination %v", dstType)
	}
	structType := dstType.Elem()
	if structType.Kind() != reflect.Struct {
		return nil, fmt.Errorf("meddler called with pointer to non-struct %v", dstType)
	}

	// gather the list of fields in the struct
	data := new(structData)
	data.fields = make(map[string]*structField)

	for i := 0; i < structType.NumField(); i++ {
		f := structType.Field(i)

		// skip non-exported fields
		if f.PkgPath != "" {
			continue
		}

		// examine the tag for metadata
		tag := strings.Split(f.Tag.Get(tagName), ",")

		// was this field marked for skipping?
		if len(tag) > 0 && tag[0] == "-" {
			continue
		}

		// default to the field name
		name := f.Name

		// the tag can override the field name
		if len(tag) > 0 && tag[0] != "" {
			name = tag[0]
		} else {
			// use mapper func if field has no explicit tag
			name = Mapper(f.Name)
		}

		// check for a meddler
		var meddler Meddler = registry["identity"]
		for j := 1; j < len(tag); j++ {
			if tag[j] == "pk" {
				if f.Type.Kind() == reflect.Ptr {
					return nil, fmt.Errorf("meddler found field %s which is marked as the primary key but is a pointer", f.Name)
				}

				// make sure it is an int of some kind
				switch f.Type.Kind() {
				case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
				case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
				default:
					return nil, fmt.Errorf("meddler found field %s which is marked as the primary key, but is not an integer type", f.Name)
				}

				if data.pk != "" {
					return nil, fmt.Errorf("meddler found field %s which is marked as the primary key, but a primary key field was already found", f.Name)
				}
				data.pk = name
			} else if m, present := registry[tag[j]]; present {
				meddler = m
			} else {
				return nil, fmt.Errorf("meddler found field %s with meddler %s, but that meddler is not registered", f.Name, tag[j])
			}
		}

		if _, present := data.fields[name]; present {
			return nil, fmt.Errorf("meddler found multiple fields for column %s", name)
		}
		data.fields[name] = &structField{
			column:     name,
			primaryKey: name == data.pk,
			index:      i,
			meddler:    meddler,
		}
		data.columns = append(data.columns, name)
	}

	fieldsCache[dstType] = data
	return data, nil
}
631287
func getFieldValue(obj interface{}, key interface{}) interface{} {
	var value reflect.Value
	val := reflect.ValueOf(obj)
	if val.Kind() == reflect.Ptr {
		val = val.Elem()
	}
	switch val.Kind() {
	case reflect.Struct:
		value = val.FieldByName(key.(string))
	case reflect.Map:
		value = val.MapIndex(reflect.ValueOf(key))
	case reflect.Slice:
		if index, ok := key.(int); !ok {
			return nil
		} else if index >= 0 || val.Len() > index {
			value = val.Index(index)
		}
	}
	if !value.IsValid() {
		return nil
	}
	return value.Interface()
}
1124083
func (i *Index) MeasurementTagKeysByExpr(name []byte, expr influxql.Expr) (map[string]struct{}, error) {
	n := i.availableThreads()

	// Store results.
	keys := make([]map[string]struct{}, i.PartitionN)
	errC := make(chan error, i.PartitionN)

	var pidx uint32 // Index of maximum Partition being worked on.
	for k := 0; k < n; k++ {
		go func() {
			for {
				idx := int(atomic.AddUint32(&pidx, 1) - 1) // Get next partition to work on.
				if idx >= len(i.partitions) {
					return // No more work.
				}

				// This is safe since there are no readers on keys until all
				// the writers are done.
				tagKeys, err := i.partitions[idx].MeasurementTagKeysByExpr(name, expr)
				keys[idx] = tagKeys
				errC <- err
			}
		}()
	}

	// Check for error
	for i := 0; i < cap(errC); i++ {
		if err := <-errC; err != nil {
			return nil, err
		}
	}

	// Merge into single map.
	result := keys[0]
	for k := 1; k < len(i.partitions); k++ {
		for k := range keys[k] {
			result[k] = struct{}{}
		}
	}
	return result, nil
}