github.com/roninzo/structs (go): Package structs implements a generic interface for manipulating Go structs. The related API is powered and inspired from the Go reflection package.  It was initially developed to provide generic field getters and setters for any struct. It has grown into an generic abstraction layer to structs powered by the reflect package.  While not being particularly performant compared to other structs packages, it provides a "natural feel" API, convenience, flexibility and simpler alternative compared to using the reflect package directly.  Throughout the documentation, the t variable is assumed to be of type struct T. T has two fields: the first is a string field called "Property" and the second is a nested struct via a pointer called "Nested". While "Property" is set to value "Test", "Number" inside "Nested" is set to 123456.  NOTE: the same applies to all other variables subsequently declared.  The following input are supported throughout the package:  NOTE: See the IndirectStruct method for details on the above scenarios.  There are two main ways to use for this package to manipulate structs. Either by using the objects and methods or by using helper functions.  Objects and methods: this approach requires calling of the New method first, which gives access to the API of the StructValue, StructField and StructFields objects.  Helper functions: A set of self-contained functions that hides internal implementations powered by the StructValue object, are all declared in the file called helpers.go.  The following table summarizes the above statements:  All objects in this package are linked to the main StructValue object. The relationships between each one of them are as follow:  NOTE: For an exhaustive illustration of package capabilities, please refer to the following file: https://github.com/roninzo/structs/example_test.go.  The StructValue object is the starting point for manipulating structs using objects and methods. To initialize the StructValue object, make use of the New method followed by handling any potential error encountered in this process.  Example:  From there, several methods provides information about the struct.  Example:  NOTE: When possible, all object method names were inspired from  the reflect package, trying to reduce the learning curve.  Example:  The StructValue object is also the gateway to the other two objects declared in this package: StructField and StructFields.  Examples:  The StructField object represents one field in the struct, and provides getters and setters methods.  Before reading data out of struct fields generically, it is recommended to get extra information about the struct field. This is useful if the type of the field is not known at runtime.  Example:  However, if nested struct are present inside t, sub-fields are not made available directly. This means that nested structs must be loaded explicitly with the Struct method.  Example:  The StructFields object represents all the fields in the struct. Its main purpose at the moment, is to loop through StructField objects in a "for range" loop.  Example:  The other purpose, is to return all struct filed names:  Example:  The StructRows object represents the slice of structs and mostly follows the database/sql API. Its main purpose is to loop through elements of a submitted slice of structs. Each of those elements can then be manipulated in the same manner as the StructValue.  Example:  The helper methods in the helpers.go provide advanced functions for transforming structs or wrap StructValue object functionalities.  Examples:
Keywords: go|golang|reflect|struct|structs