Documentation
¶
Index ¶
- Constants
- func AutoMapper(fromObj, toObj interface{}) error
- func CheckExistsField(elem reflect.Value, fieldName string) (realFieldName string, exists bool)
- func CheckIsTypeWrapper(value reflect.Value) bool
- func GetFieldName(objElem reflect.Value, index int) string
- func GetTimeJSONFormat() string
- func GetTypeName(obj interface{}) string
- func IsEnabledCustomTag() bool
- func JsonToMap(body []byte, toMap *map[string]interface{}) error
- func MapToJson(fromMap map[string]interface{}) ([]byte, error)
- func MapToSlice(fromMap map[string]interface{}, toSlice interface{}) error
- func Mapper(fromObj, toObj interface{}) error
- func MapperMap(fromMap map[string]interface{}, toObj interface{}) error
- func MapperMapSlice(fromMaps map[string]map[string]interface{}, toSlice interface{}) error
- func MapperSlice(fromSlice, toSlice interface{}) error
- func PackageVersion() string
- func Register(obj interface{}) error
- func SetCustomTagName(tagName string)
- func SetEnableFieldIgnoreTag(isEnabled bool)
- func SetEnabledAutoTypeConvert(isEnabled bool)
- func SetEnabledCustomTag(isEnabled bool)
- func SetEnabledJsonTag(isEnabled bool)
- func SetEnabledMapperStructField(isEnabled bool)
- func SetEnabledMapperTag(isEnabled bool)
- func SetEnabledTypeChecking(isEnabled bool)
- func SetTimeJSONFormat(format string)
- func TimeToUnix(t time.Time) int64
- func TimeToUnixLocation(t time.Time, location string) (int64, error)
- func ToInt64(value interface{}) (d int64)
- func ToString(value interface{}, args ...int) (s string)
- func UnixToTime(tt int64) time.Time
- func UnixToTimeLocation(tt int64, location string) (time.Time, error)
- func UseWrapper(w TypeWrapper)
- type BaseTypeWrapper
- type Convert
- func (f Convert) Bool() (bool, error)
- func (f *Convert) Clear()
- func (f Convert) Exist() bool
- func (f Convert) Float32() (float32, error)
- func (f Convert) Float64() (float64, error)
- func (f Convert) Int() (int, error)
- func (f Convert) Int16() (int16, error)
- func (f Convert) Int32() (int32, error)
- func (f Convert) Int64() (int64, error)
- func (f Convert) Int8() (int8, error)
- func (f *Convert) Set(v string)
- func (f Convert) String() string
- func (f Convert) Uint() (uint, error)
- func (f Convert) Uint16() (uint16, error)
- func (f Convert) Uint32() (uint32, error)
- func (f Convert) Uint64() (uint64, error)
- func (f Convert) Uint8() (uint8, error)
- type IMapper
- type JSONTime
- type Option
- func CAutoTypeConvert(isEnabled bool) Option
- func CCustomTag(isEnabled bool) Option
- func CCustomTagName(tagName string) Option
- func CFieldIgnoreTag(isEnabled bool) Option
- func CJsonTag(isEnabled bool) Option
- func CMapperStructField(isEnabled bool) Option
- func CMapperTag(isEnabled bool) Option
- func CTypeChecking(isEnabled bool) Option
- type Setting
- type TimeWrapper
- type TypeWrapper
Constants ¶
const ( IgnoreTagValue = "-" CompositeFieldTagValue = "composite-field" )
Variables ¶
This section is empty.
Functions ¶
func AutoMapper ¶
func AutoMapper(fromObj, toObj interface{}) error
AutoMapper mapper and set value from struct fromObj to toObj support auto register struct
func CheckExistsField ¶
CheckExistsField check field is exists by name
func CheckIsTypeWrapper ¶
CheckIsTypeWrapper check value is in type wrappers
func GetFieldName ¶
GetFieldName get fieldName with ElemValue and index if config tag string, return tag value
func GetTimeJSONFormat ¶
func GetTimeJSONFormat() string
func IsEnabledCustomTag ¶ added in v0.7.13
func IsEnabledCustomTag() bool
func MapToSlice ¶
MapToSlice mapper from map[string]interface{} to a slice of any type's ptr toSlice must be a slice of any type.
func Mapper ¶
func Mapper(fromObj, toObj interface{}) error
Mapper mapper and set value from struct fromObj to toObj not support auto register struct
func MapperMap ¶
MapperMap mapper and set value from map to object support auto register struct now support field type: 1.reflect.Bool 2.reflect.String 3.reflect.Int8\16\32\64 4.reflect.Uint8\16\32\64 5.reflect.Float32\64 6.time.Time
func MapperMapSlice ¶
MapperMapSlice mapper from map[string]map[string]interface{} to a slice of any type's ptr toSlice must be a slice of any type. Deprecated: will remove on v1.0, please use MapToSlice instead
func MapperSlice ¶
func MapperSlice(fromSlice, toSlice interface{}) error
MapperSlice mapper from slice of struct to a slice of any type fromSlice and toSlice must be a slice of any type.
func PackageVersion ¶
func PackageVersion() string
func SetEnableFieldIgnoreTag ¶ added in v0.7.10
func SetEnableFieldIgnoreTag(isEnabled bool)
SetEnableFieldIgnoreTag set the enabled flag for the ignored tag in the version < 0.7.8, we use field name as the key when mapping structs if field tag is "-" from 0.7.8, we add switch enableFieldIgnoreTag which is false in default if caller enable this flag, the field will be ignored in the mapping process
func SetEnabledAutoTypeConvert ¶
func SetEnabledAutoTypeConvert(isEnabled bool)
SetEnabledAutoTypeConvert set enabled flag for auto type convert if set true, field will auto convert in Time and Unix default is true
func SetEnabledCustomTag ¶ added in v0.7.13
func SetEnabledCustomTag(isEnabled bool)
SetEnabledCustomTag set enabled flag for set custom tag name if set true and set customTagName, the custom tag will be check during mapping's GetFieldName default is false
func SetEnabledJsonTag ¶
func SetEnabledJsonTag(isEnabled bool)
SetEnabledJsonTag set enabled flag for 'Json' tag check if set true, 'Json' tag will be check during mapping's GetFieldName default is true
func SetEnabledMapperStructField ¶
func SetEnabledMapperStructField(isEnabled bool)
SetEnabledMapperStructField set enabled flag for MapperStructField if set true, the reflect.Struct field will auto mapper must follow premises: 1. fromField and toField type must be reflect.Struct and not time.Time 2. fromField and toField must be not same type default is enabled
func SetEnabledMapperTag ¶
func SetEnabledMapperTag(isEnabled bool)
SetEnabledMapperTag set enabled flag for 'Mapper' tag check if set true, 'Mapper' tag will be check during mapping's GetFieldName default is true
func SetEnabledTypeChecking ¶
func SetEnabledTypeChecking(isEnabled bool)
SetEnabledTypeChecking set enabled flag for TypeChecking if set true, the field type will be checked for consistency during mapping default is false
func SetTimeJSONFormat ¶
func SetTimeJSONFormat(format string)
func TimeToUnix ¶
TimeToUnix transform time to Unix time, the number of seconds elapsed
func TimeToUnixLocation ¶
TimeToUnixLocation transform time to Unix time with time location location like "Asia/Shanghai"
func UnixToTimeLocation ¶
UnixToTimeLocation transform Unix time to local Time with time location location like "Asia/Shanghai"
Types ¶
type BaseTypeWrapper ¶
type BaseTypeWrapper struct {
// contains filtered or unexported fields
}
func (*BaseTypeWrapper) SetNext ¶
func (bm *BaseTypeWrapper) SetNext(m TypeWrapper)
type IMapper ¶ added in v0.7.10
type IMapper interface { Mapper(fromObj, toObj interface{}) error AutoMapper(fromObj, toObj interface{}) error MapperMap(fromMap map[string]interface{}, toObj interface{}) error MapToSlice(fromMap map[string]interface{}, toSlice interface{}) error MapperMapSlice(fromMaps map[string]map[string]interface{}, toSlice interface{}) error MapperSlice(fromSlice, toSlice interface{}) error MapToJson(fromMap map[string]interface{}) ([]byte, error) JsonToMap(body []byte, toMap *map[string]interface{}) error Register(obj interface{}) error UseWrapper(w TypeWrapper) GetTypeName(obj interface{}) string GetFieldName(objElem reflect.Value, index int) string GetCustomTagName() string GetDefaultTimeWrapper() *TimeWrapper CheckExistsField(elem reflect.Value, fieldName string) (realFieldName string, exists bool) CheckIsTypeWrapper(value reflect.Value) bool SetEnabledTypeChecking(isEnabled bool) IsEnabledTypeChecking() bool SetEnabledMapperTag(isEnabled bool) IsEnabledMapperTag() bool SetEnabledJsonTag(isEnabled bool) IsEnabledJsonTag() bool SetEnabledCustomTag(isEnabled bool) IsEnabledCustomTag() bool SetCustomTagName(tagName string) SetEnabledAutoTypeConvert(isEnabled bool) IsEnabledAutoTypeConvert() bool SetEnabledMapperStructField(isEnabled bool) IsEnabledMapperStructField() bool SetEnableFieldIgnoreTag(isEnabled bool) IsEnableFieldIgnoreTag() bool }
type Option ¶ added in v0.7.14
type Option func(*Setting)
Option 用于设置 Config 结构体的字段。
func CAutoTypeConvert ¶ added in v0.7.14
func CCustomTag ¶ added in v0.7.14
func CCustomTagName ¶ added in v0.7.14
func CFieldIgnoreTag ¶ added in v0.7.14
func CMapperStructField ¶ added in v0.7.14
func CTypeChecking ¶ added in v0.7.14
CTypeChecking set EnabledTypeChecking value
Default value: false
type Setting ¶ added in v0.7.14
type Setting struct { EnabledTypeChecking bool EnabledMapperStructField bool EnabledAutoTypeConvert bool EnabledMapperTag bool EnabledJsonTag bool EnabledCustomTag bool CustomTagName string // in the version < 0.7.8, we use field name as the key when mapping structs if field tag is "-" // from 0.7.8, we add switch enableIgnoreFieldTag which is false in default // if caller enable this flag, the field will be ignored in the mapping process EnableFieldIgnoreTag bool }
func NewSetting ¶ added in v0.7.14
NewSetting create new setting with multi option
type TimeWrapper ¶
type TimeWrapper struct {
BaseTypeWrapper
}
func NewTimeWrapper ¶
func NewTimeWrapper() *TimeWrapper
type TypeWrapper ¶
type TypeWrapper interface { IsType(value reflect.Value) bool SetNext(m TypeWrapper) }