package
1.4.0
Repository: https://github.com/jmoiron/sqlx.git
Documentation: pkg.go.dev

# README

reflectx

The sqlx package has special reflect needs. In particular, it needs to:

  • be able to map a name to a field
  • understand embedded structs
  • understand mapping names to fields by a particular tag
  • user specified name -> field mapping functions

These behaviors mimic the behaviors by the standard library marshallers and also the behavior of standard Go accessors.

The first two are amply taken care of by Reflect.Value.FieldByName, and the third is addressed by Reflect.Value.FieldByNameFunc, but these don't quite understand struct tags in the ways that are vital to most marshallers, and they are slow.

This reflectx package extends reflect to achieve these goals.

# Functions

Deref is Indirect for reflect.Types.
FieldByIndexes returns a value for the field given by the struct traversal for the given value.
FieldByIndexesReadOnly returns a value for a particular struct traversal, but is not concerned with allocating nil pointers because the value is going to be used for reading and not setting.
NewMapper returns a new mapper using the tagName as its struct field tag.
NewMapperFunc returns a new mapper which optionally obeys a field tag and a struct field name mapper func given by f.
NewMapperTagFunc returns a new mapper which contains a mapper for field names AND a mapper for tag values.

# Structs

A FieldInfo is metadata for a struct field.
Mapper is a general purpose mapper of names to struct fields.
A StructMap is an index of field metadata for a struct.