// fieldByTag returns the value for the field in x with the given JSON tag, or "" if there is no such field.
552832
func fieldByTag(x interface{}, tag string) string {
	tagm := tags(x)
	v := reflect.ValueOf(x)
	if v.Kind() == reflect.Ptr {
		v = v.Elem()
	}
	if i, ok := tagm[tag]; ok {
		return v.Field(i).Interface().(string)
	}
	return ""
}
1181926
func fieldAlias(field reflect.StructField, tagName string) (alias string, options tagOptions) {
	if tag := field.Tag.Get(tagName); tag != "" {
		alias, options = parseTag(tag)
	}
	if alias == "" {
		alias = field.Name
	}
	return alias, options
}
987591
func (c IndexEntries) BytesByTag(tag int) []byte {
	i := c.IndexByTag(tag)
	if i == nil || i.Value == nil {
		return nil
	}
	b, ok := i.Value.([]byte)
	if !ok {
		return nil
	}
	return b
}
1242286
func (scope *Scope) FieldByName(name string) (field *Field, ok bool) {
	var (
		dbName           = ToColumnName(name)
		mostMatchedField *Field
	)

	for _, field := range scope.Fields() {
		if field.Name == name || field.DBName == name {
			return field, true
		}
		if field.DBName == dbName {
			mostMatchedField = field
		}
	}
	return mostMatchedField, mostMatchedField != nil
}
655981
func (b *block) Tag() (names.Tag, error) {
	tag, err := names.ParseTag(b.doc.Tag)
	if err != nil {
		return nil, errors.Annotatef(err, "getting block information")
	}
	return tag, nil
}
923091
func queryByTag(c context.Context, pkg, tag string, cursor datastore.Cursor, pageSize int32) (
	out []*datastore.Key,
	next datastore.Cursor,
	err error) {

	// TODO(vadimsh): 'registered_ts' here is when the tag was attached. The
	// callers likely expect results ordered by instance registration time. This
	// is not possible currently. We'll need to copy Instance.registered_ts into
	// InstanceTag entities, so we can order by instance registration time.

	// TODO(vadimsh): Should we exclude unprocessed instances from the result?

	q := datastore.NewQuery("InstanceTag").
		Ancestor(PackageKey(c, pkg)).
		Eq("tag", tag).
		Order("-registered_ts").
		Limit(pageSize).
		KeysOnly(true)
	if cursor != nil {
		q = q.Start(cursor)
	}

	err = datastore.Run(c, q, func(k *datastore.Key, cb datastore.CursorCB) error {
		out = append(out, k.Parent())
		if len(out) >= int(pageSize) {
			if next, err = cb(); err != nil {
				return err
			}
			return datastore.Stop
		}
		return nil
	})
	if err != nil {
		return nil, nil, errors.Annotate(err, "failed to query by tag %q", tag).Tag(transient.Tag).Err()
	}
	return
}
263050
func (d *Dataset) Tag(index int, tags ...string) error {
	if index < 0 || index >= d.rows {
		return ErrInvalidRowIndex
	}

	for _, tag := range tags {
		if !isTagged(tag, d.tags[index]) {
			d.tags[index] = append(d.tags[index], tag)
		}
	}

	return nil
}
427258
func (f *Field) AddTag(tag string) FieldInterface {
	f.tag[tag] = struct{}{}
	return f
}
775008
func (p *Path) Tag(tags ...string) *Path {
	np := p.clone()
	np.stack = append(np.stack, tagMorphism(tags...))
	return np
}
492840
func Tags(tags ...string) func(*Context) error {
	return func(c *Context) error {
		c.buildtags = append(c.buildtags, tags...)
		return nil
	}
}
1368909
func (c *DeleteManyBuildsCall) Tag(tag ...string) *DeleteManyBuildsCall {
	c.urlParams_.SetMulti("tag", append([]string{}, tag...))
	return c
}
235042
func Tags(obj interface{}, key string) (map[string]string, error) {
	return tags(obj, key, false)
}
589875
func ErrorByField(e error, field string) string {
	if e == nil {
		return ""
	}
	return ErrorsByField(e)[field]
}
793207
func (c IndexEntries) IntByTag(tag int) int64 {
	i := c.IndexByTag(tag)
	if i != nil && i.Value != nil {
		switch i.Type {
		case IndexDataTypeChar, IndexDataTypeInt8:
			v, ok := i.Value.([]int8)
			if !ok {
				return 0
			}
			return int64(v[0])

		case IndexDataTypeInt16:
			v, ok := i.Value.([]int16)
			if !ok {
				return 0
			}
			return int64(v[0])

		case IndexDataTypeInt32:
			v, ok := i.Value.([]int32)
			if !ok {
				return 0
			}
			return int64(v[0])

		case IndexDataTypeInt64:
			v, ok := i.Value.([]int64)
			if !ok {
				return 0
			}
			return v[0]
		}
	}

	return 0
}
1107689
func GetFieldByTag(ival interface{}, tagName string, fieldNames []string) (interface{}, error) {
	if len(fieldNames) == 0 {
		return nil, trace.BadParameter("missing field names")
	}
	val := reflect.ValueOf(ival)
	if val.Kind() == reflect.Interface || val.Kind() == reflect.Ptr {
		val = val.Elem()
	}
	if val.Kind() != reflect.Struct {
		return nil, trace.NotFound("field name %v is not found", strings.Join(fieldNames, "."))
	}
	fieldName := fieldNames[0]
	rest := fieldNames[1:]

	valType := val.Type()
	for i := 0; i < valType.NumField(); i++ {
		tagValue := valType.Field(i).Tag.Get(tagName)
		parts := strings.Split(tagValue, ",")
		if parts[0] == fieldName {
			value := val.Field(i).Interface()
			if len(rest) == 0 {
				return value, nil
			}
			return GetFieldByTag(value, tagName, rest)
		}
	}
	return nil, trace.NotFound("field name %v is not found", strings.Join(fieldNames, "."))
}
1221149
func (g *Group) Tag(items map[string]string) *Statement {
	// notest
	// don't think this can ever be used in valid code?
	s := Tag(items)
	g.items = append(g.items, s)
	return s
}
479151
func (f Form) InputTag(opts tags.Options) *tags.Tag {
	if opts["type"] == "hidden" {
		return f.HiddenTag(opts)
	}

	if opts["type"] == nil {
		opts["type"] = "text"
	}

	if opts["type"] == "file" {
		f.Options["enctype"] = "multipart/form-data"
	}

	delete(opts, "tag_only")
	return tags.New("input", opts)
}