Documentation ¶
Overview ¶
Golf (Go List Fields) enables retrieving a map of an object's field names and values through either interface implementation or reflection.
Index ¶
Constants ¶
const ( // A field's JSON and Golf tags are both inspected with preference given to // the Golf tags. This is the default. PreferGolfTags = iota // A field's JSON and Golf tags are both inspected with preference given to // the JSON tags. PreferJsonTags // A field's JSON tags are ignored and only the Golf tags are used. IgnoreJsonTags // A field's Golf tags are ignored and only the JSON tags are used. IgnoreGolfTags )
const ( // One of the following types: // // - Array // - Chan // - Func // - Interface // - Map // - Array // - Ptr // - Slice // - UnsafePointer NilKind = iota // One of the following types: // // - Int // - Int8 // - Int16 // - Int32 // - Int64 // - Uint // - Uint8 // - Uint16 // - Uint32 // - Uint64 // - Uintptr // - Float32 // - Float64 // - Complex64 // - Complex128 ValueKind // A string type StringKind // A struct type StructKind )
Variables ¶
This section is empty.
Functions ¶
func Fore ¶
This function will inspect an object to see if it implements the GolfsWithExportedFields interface first and foremost in order to enable non-struct types to return a map of field name/value data from the GolfExportedFields function.
However, if the GolfExportedFields function returns nil and the provided object is a struct, reflection will be used to gather information about field names and values.
Regardless of whether the GolfExportedFields map or data gathered through reflection is used, this function will recurse into the top-level data in order to map out the object graph, producing key/value pairs and adding them to the returned map for the entire graph.
Types ¶
type Golfs ¶
type Golfs interface { // PlayGolf is a dummy function that has no impact on anything other than // supplying an empty interface with a way to be implemented. PlayGolf() bool }
Golfs is an interface implemented by types in order to indicate to external packages that the type is aware that Golf may be used, thus giving the external package a way to test if a type is golf-aware.
type GolfsWithExportedFields ¶
type GolfsWithExportedFields interface { // GolfExportedFields returns a map of the exported field names and their // values. GolfExportedFields() map[string]interface{} }
GolfsWithExportedFields is an interface implemented by types in order to return a map of explicit field names and values.
If this function returns nil, and the inspected type is a struct then reflection is used to infer the object's field names and values.
type GolfsWithJsonTagBehavior ¶
type GolfsWithJsonTagBehavior interface { // GolfJsonTagBehavior returns an integer that dictates how a field's // possible JSON tags should be treated. // // 0 - A field's JSON and Golf tags are both inspected with preference // given to the Golf tags. // // 1 - A field's JSON and Golf tags are both inspected with preference // given to the JSON tags. // // 2 - A field's JSON tags are ignored and only the Golf tags are used. // // 3 - A field's Golf tags are ignored and only the JSON tags are used. GolfJsonTagBehavior() int }
GolfsWithJsonTagBehavior is an interface impelemented by types in order to influence the logic of how a struct's field's tags are handled when reflection is used to infer an object's field names and values. This interface is only valid for struct types and will be ignored for others.