Documentation
¶
Overview ¶
This package provides some punk-rock reflection which is not in the stdlib.
Index ¶
- Constants
- func FieldsAndValues(val interface{}) ([]string, []interface{}, bool)
- func MapToStruct(m map[string]interface{}, struc interface{}) error
- func StructFieldMap(structType r.Type, lowercaseFields bool) (map[string]Field, error)
- func StructToMap(val interface{}) (map[string]interface{}, bool)
- type Field
Constants ¶
const TagName = "cql"
Variables ¶
This section is empty.
Functions ¶
func FieldsAndValues ¶
FieldsAndValues returns a list field names and a corresponding list of values for the given struct. For details on how the field names are determined please see StructToMap.
func MapToStruct ¶
MapToStruct converts a map to a struct. It is the inverse of the StructToMap function. For details see StructToMap.
func StructFieldMap ¶
StructFieldMap takes a struct type and extracts the Field info into a map by field name. The "cql" key in the struct field's tag value is the key name. Examples:
// Field appears in the resulting map as key "myName". Field int `cql:"myName"` // Field appears in the resulting as key "Field" Field int // Field appears in the resulting map as key "myName" Field int "myName"
If lowercaseFields is set to true, field names are lowercased in the map
func StructToMap ¶
StructToMap converts a struct to map. The object's default key string is the struct field name but can be specified in the struct field's tag value. The "cql" key in the struct field's tag value is the key name. Examples:
// Field appears in the resulting map as key "myName". Field int `cql:"myName"` // Field appears in the resulting as key "Field" Field int // Field appears in the resulting map as key "myName" Field int "myName"