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 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 SetEnabledAutoTypeConvert(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 JSONTime
- type TimeWrapper
- type TypeWrapper
Constants ¶
const (
IgnoreTagValue = "-"
)
Variables ¶
This section is empty.
Functions ¶
func AutoMapper ¶
func AutoMapper(fromObj, toObj interface{}) error
Mapper 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 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 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 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)
SetEnabledTypeChecking 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 TimeWrapper ¶
type TimeWrapper struct {
BaseTypeWrapper
}
var ( ZeroValue reflect.Value DefaultTimeWrapper *TimeWrapper )
func NewTimeWrapper ¶
func NewTimeWrapper() *TimeWrapper
type TypeWrapper ¶
type TypeWrapper interface {
IsType(value reflect.Value) bool
SetNext(m TypeWrapper)
}