reflectx: code ported from github.com/jmoiron/sqlx a2429ba

Depending on sqlx makes users pull SQL related code that is usually not
needed. Tools like dep make it easier by explicitly listing relevant
subpackages but the code needs to be downloaded anyway.
This commit is contained in:
Michał Matczuk
2018-05-25 10:57:26 +02:00
parent 1fec441dbc
commit aef66f4663
7 changed files with 1436 additions and 4 deletions

17
reflectx/README.md Normal file
View File

@@ -0,0 +1,17 @@
# 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.