typeTransform

package
v0.0.0-...-05317bf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2015 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func FloatToFloat

func FloatToFloat(t Transformer, in reflect.Value, out reflect.Value) (err error)

func FloatToInt

func FloatToInt(t Transformer, in reflect.Value, out reflect.Value) (err error)

func FloatToString

func FloatToString(t Transformer, in reflect.Value, out reflect.Value) (err error)

func IntToInt

func IntToInt(t Transformer, in reflect.Value, out reflect.Value) (err error)

func IntToString

func IntToString(t Transformer, in reflect.Value, out reflect.Value) (err error)

func InterfaceToNoneInterface

func InterfaceToNoneInterface(t Transformer, in reflect.Value, out reflect.Value) (err error)

func MapToMap

func MapToMap(t Transformer, in reflect.Value, out reflect.Value) (err error)

func MapToStruct

func MapToStruct(t Transformer, in reflect.Value, out reflect.Value) (err error)

假设map的key类型是string,值类型不限

func MustTransform

func MustTransform(in interface{}, out interface{})

func MustTransformToMap

func MustTransformToMap(in interface{}) (m map[string]string)

func NoneInterfaceToInterface

func NoneInterfaceToInterface(t Transformer, in reflect.Value, out reflect.Value) (err error)

func NonePtrToPtr

func NonePtrToPtr(t Transformer, in reflect.Value, out reflect.Value) (err error)

func PtrToPtr

func PtrToPtr(t Transformer, in reflect.Value, out reflect.Value) (err error)

func SliceStructToMapStruct

func SliceStructToMapStruct(in interface{}, out interface{}, idFieldName string) (err error)

transform slice of struct to map of struct, it will report error if Id is not unique 有Id重复验证

func SliceToSlice

func SliceToSlice(t Transformer, in reflect.Value, out reflect.Value) (err error)

func StringToBool

func StringToBool(t Transformer, in reflect.Value, out reflect.Value) (err error)

"" => false

func StringToFloat

func StringToFloat(t Transformer, in reflect.Value, out reflect.Value) (err error)

"" => 0.0

func StringToInt

func StringToInt(t Transformer, in reflect.Value, out reflect.Value) (err error)

"" => 0

func StringToString

func StringToString(t Transformer, in reflect.Value, out reflect.Value) (err error)

func StringToTime

func StringToTime(traner Transformer, in reflect.Value, out reflect.Value) (err error)

func StringToUint

func StringToUint(t Transformer, in reflect.Value, out reflect.Value) (err error)

"" => 0

func StringTransformSubType

func StringTransformSubType(in interface{}, transformTable map[string]map[string]string) (err error)

transform some string on some sub type base on type full name can be general by callback base on type all value must exist in that transformTable specal case: 1."" -> ""

func StructFieldCopy

func StructFieldCopy(in interface{}, out interface{})

copy fields value between two pointer of struct, it will copy value with same field name in two struct it ignore not share field name it ignore share field name with not same type it ignore field can not set (it is addressable and was not obtained by the use of unexported struct fields)

func StructToMap

func StructToMap(t Transformer, in reflect.Value, out reflect.Value) (err error)

假设map的key类型是string,值类型不限

func TimeToString

func TimeToString(traner Transformer, in reflect.Value, out reflect.Value) (err error)

func ToString

func ToString(in interface{}) (out string, err error)

func ToStringReflect

func ToStringReflect(in reflect.Value) (out string, err error)

func Transform

func Transform(in interface{}, out interface{}) (err error)

try best transform one type to another type special case: "" => 0 "" => 0.0

Types

type Kind

type Kind uint

golang的kind分的太细

const (
	Invalid Kind = iota
	String
	Int
	Float
	Ptr
	Bool
	Time
	Interface
	Map
	Struct
	Slice
	Array
	Uint
)

func GetReflectKind

func GetReflectKind(in reflect.Value) Kind

func (Kind) String

func (k Kind) String() string

type Transformer

type Transformer map[Kind]map[Kind]TransformerFunc

func (Transformer) Clone

func (t Transformer) Clone() Transformer

func (Transformer) Tran

func (t Transformer) Tran(in reflect.Value, out reflect.Value) (err error)

func (Transformer) Transform

func (t Transformer) Transform(in interface{}, out interface{}) (err error)

type TransformerFunc

type TransformerFunc func(traner Transformer, in reflect.Value, out reflect.Value) (err error)

func NewStringToTimeFunc

func NewStringToTimeFunc(location *time.Location) TransformerFunc

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL