Documentation ¶
Index ¶
- Constants
- func FieldExists(obj interface{}, fieldName string) bool
- func GetExportableFieldsByJSONTag(obj interface{}) []string
- func GetFieldNamesByTagKeyExistence(obj interface{}, tagName string, tagKey string) []string
- func GetFieldTagKeyValue(obj interface{}, fieldName string, tagName string, tagKey string) string
- func GetFieldType(obj interface{}, fieldName string) string
- func GetFieldTypeName(obj interface{}, fieldName string) string
- func GetFieldValue(obj interface{}, fieldName string) interface{}
- func GetFieldsByTagExistence(obj interface{}, tagName string) []string
- func GetName(obj interface{}) string
- func GetNestedFieldReflectValue(val reflect.Value, path string) (reflect.Value, error)
- func GetPointerStructValue(obj interface{}) interface{}
- func GetType(obj interface{}) string
- func IsFieldTagExists(obj interface{}, fieldName string, tagName string) bool
- func IsFieldTagExistsExt(obj interface{}, fieldName string, tagName string) (tagExists bool, isFieldFound bool)
- func IsFieldTagKeyExists(obj interface{}, fieldName string, tagName string, tagKey string) bool
- func IsPlainStruct(obj interface{}) bool
- func IsPointer(obj interface{}) bool
- func IsStruct(obj interface{}) bool
- func SetAny(obj interface{}, fieldName string, val interface{}) bool
- func SetBool(obj interface{}, fieldName string, val bool) bool
- func SetDefaultValues(obj interface{}) error
- func SetInterface(obj interface{}, fieldName string, val interface{}) bool
- func SetUUID(obj interface{}, fieldName string, val uuid.UUID) bool
- func StrStrToStrInterface(obj map[string]string) map[string]interface{}
- type Helper
- func (h *Helper) Bool(fieldName string, val bool) bool
- func (h *Helper) FieldExists(fieldName string) bool
- func (h *Helper) FillMap(out map[string]interface{})
- func (h *Helper) GetFieldNamesByTagKeyExistence(tagName string, tagKey string) []string
- func (h *Helper) GetFieldReflectType(fieldName string) reflect.Type
- func (h *Helper) GetFieldTag(fieldName string) string
- func (h *Helper) GetFieldTagKeyValue(fieldName string, tagName string, tagKey string) string
- func (h *Helper) GetFieldTagValue(fieldName string, tagName string) string
- func (h *Helper) GetFieldType(fieldName string) string
- func (h *Helper) GetFieldTypeName(fieldName string) string
- func (h *Helper) GetFieldValue(fieldName string) interface{}
- func (h *Helper) GetFieldsByTagExistence(tagName string) []string
- func (h *Helper) GetPointerStructValue() interface{}
- func (h *Helper) GetTagValByInputRef(inputRef *InputRef, fieldName string, tagName string) string
- func (h *Helper) GetType() string
- func (h *Helper) IsFieldTagExists(fieldName string, tagName string) bool
- func (h *Helper) IsFieldTagExistsExt(fieldName string, tagName string) (tagExists bool, isFieldFound bool)
- func (h *Helper) IsFieldTagKeyExists(inputRef *InputRef, fieldName string, tagName string, tagKey string) bool
- func (h *Helper) IsPointer() bool
- func (h *Helper) Map() map[string]interface{}
- func (h *Helper) SetAny(fieldName string, val interface{}) bool
- func (h *Helper) SetBool(fieldName string, val bool) bool
- func (h *Helper) SetInterface(fieldName string, val interface{}) bool
- func (h *Helper) SetUUID(fieldName string, val uuid.UUID) bool
- func (h *Helper) StructFields() []reflect.StructField
- type InputRef
Constants ¶
const ( InvalidObjType = "obj type should be non-pointer and type struct" InvalidPointerObjType = "obj type should be pointer and type struct" )
const (
DefaultTagName = "structs"
)
Variables ¶
This section is empty.
Functions ¶
func FieldExists ¶
func GetExportableFieldsByJSONTag ¶
func GetExportableFieldsByJSONTag(obj interface{}) []string
TODO: move or rename this func
func GetFieldNamesByTagKeyExistence ¶
GetFieldNamesByTagKeyExistence -> it will return the field names
func GetFieldTagKeyValue ¶
func GetFieldType ¶
func GetFieldTypeName ¶
func GetFieldValue ¶
func GetFieldValue(obj interface{}, fieldName string) interface{}
GetFieldValue -> return a structure field value
func GetFieldsByTagExistence ¶
func GetPointerStructValue ¶
func GetPointerStructValue(obj interface{}) interface{}
func IsFieldTagExists ¶
IsFieldTagExists -> standard version
func IsFieldTagExistsExt ¶
func IsFieldTagExistsExt(obj interface{}, fieldName string, tagName string) (tagExists bool, isFieldFound bool)
IsFieldTagExistsExt -> extended
func IsFieldTagKeyExists ¶
func IsPlainStruct ¶
func IsPlainStruct(obj interface{}) bool
IsPlainStruct -> checks if it's not a pointer and it's a clear/clean struct!
func IsStruct ¶
func IsStruct(obj interface{}) bool
IsStruct -> it can be a pointer of a struct or a struct! if it's a &Struct then it will return a ptr!, it's gonna be ptr
func SetDefaultValues ¶
func SetDefaultValues(obj interface{}) error
SetDefaultValues -> Set initializes members in a struct referenced by a pointer. Maps and slices are initialized by `make` and other primitive types are set with default values. `ptr` should be a struct pointer
func SetInterface ¶
func StrStrToStrInterface ¶
Types ¶
type Helper ¶
type Helper struct { // this is the plain structure! NonPtrObj interface{} // this is the pointer to structure! PtrObj interface{} TagName string // contains filtered or unexported fields }
func (*Helper) FieldExists ¶
func (*Helper) FillMap ¶
FillMap is the same as Map. Instead of returning the output, it fills the given map.
func (*Helper) GetFieldNamesByTagKeyExistence ¶
func (*Helper) GetFieldReflectType ¶
func (*Helper) GetFieldTag ¶
func (*Helper) GetFieldTagKeyValue ¶
func (*Helper) GetFieldTagValue ¶
func (*Helper) GetFieldType ¶
func (*Helper) GetFieldTypeName ¶
func (*Helper) GetFieldValue ¶
func (*Helper) GetFieldsByTagExistence ¶
func (*Helper) GetPointerStructValue ¶
func (h *Helper) GetPointerStructValue() interface{}
func (*Helper) GetTagValByInputRef ¶
func (*Helper) IsFieldTagExists ¶
func (*Helper) IsFieldTagExistsExt ¶
func (*Helper) IsFieldTagKeyExists ¶
func (*Helper) Map ¶
Map converts the given struct to a map[string]interface{}, where the keys of the map are the field names and the values of the map the associated values of the fields. The default key string is the struct field name but can be changed in the struct field's tag value. The "structs" key in the struct's field tag value is the key name. Example:
// Field appears in map as key "myName". Name string `structs:"myName"`
A tag value with the content of "-" ignores that particular field. Example:
// Field is ignored by this package. Field bool `structs:"-"`
A tag value with the content of "string" uses the stringer to get the value. Example:
// The value will be output of Animal's String() func. // Map will panic if Animal does not implement String(). Field *Animal `structs:"field,string"`
A tag value with the option of "flatten" used in a struct field is to flatten its fields in the output map. Example:
// The FieldStruct's fields will be flattened into the output map. FieldStruct time.Time `structs:",flatten"`
A tag value with the option of "omitnested" stops iterating further if the type is a struct. Example:
// Field is not processed further by this package. Field time.Time `structs:"myName,omitnested"` Field *http.Request `structs:",omitnested"`
A tag value with the option of "omitempty" ignores that particular field if the field value is empty. Example:
// Field appears in map as key "myName", but the field is // skipped if empty. Field string `structs:"myName,omitempty"` // Field appears in map as key "Field" (the default), but // the field is skipped if empty. Field string `structs:",omitempty"`
Note that only exported fields of a struct can be accessed, non exported fields will be neglected.
func (*Helper) SetInterface ¶
func (*Helper) StructFields ¶
func (h *Helper) StructFields() []reflect.StructField
StructFields returns the exported struct fields for a given s struct. This is a convenient helper method to avoid duplicate code in some of the functions.