Documentation
¶
Index ¶
- func BoolCopyPtr(v bool) *bool
- func BoolToInt(b bool) int
- func BoolToString(b bool) string
- func Float32CopyPtr(v float32) *float32
- func Float32ToString(f float32) string
- func Float64CopyPtr(v float64) *float64
- func Float64ToString(f float64) string
- func GetOrDefault(res interface{}, defaultValue interface{}) interface{}
- func GetOrDefaultFloat64(i *float64) float64
- func GetOrDefaultInt32(i *int32) int32
- func GetOrDefaultInt64(i *int64) int64
- func GetOrDefaultString(str *string) string
- func Int16CopyPtr(v int16) *int16
- func Int32CopyPtr(v int32) *int32
- func Int32ToString(i int32) string
- func Int64CopyPtr(v int64) *int64
- func Int64PtrCopyPtr(v *int64) *int64
- func Int64ToString(i int64) string
- func Int8CopyPtr(v int8) *int8
- func IntCopyPtr(v int) *int
- func IntMeanToString(i int) string
- func IntToBool(i int) bool
- func IntToString(i int) string
- func InterfaceToFloat64(inter interface{}) float64
- func InterfaceToFloat64V2(inter interface{}) (float float64, err error)
- func InterfaceToInt(inter interface{}) int
- func InterfaceToInt64(inter interface{}) int64
- func InterfaceToJsonNum(inter interface{}) json.Number
- func InterfaceToString(inter interface{}) string
- func JsonNumberPointerToFloat64(number *json.Number) float64
- func JsonNumberPointerToInt64(number *json.Number) int64
- func JsonNumberPointerToString(number *json.Number) string
- func JsonNumberToInt(num json.Number) (int, error)
- func MapFieldFormatToString(value map[string]interface{}) map[string]interface{}
- func MapStringToStruct(originalData map[string]string, result interface{}) error
- func PtrCopyBool(v *bool) bool
- func PtrCopyFloat32(v *float32) float32
- func PtrCopyFloat64(v *float64) float64
- func PtrCopyInt(v *int) int
- func PtrCopyInt16(v *int16) int16
- func PtrCopyInt32(v *int32) int32
- func PtrCopyInt64(v *int64) int64
- func PtrCopyInt8(v *int8) int8
- func PtrCopyString(v *string) string
- func PtrCopyUint32(v *uint32) uint32
- func PtrCopyUint64(v *uint64) uint64
- func SafeUnmarshal(str []byte, ret interface{}) error
- func StringCopyPtr(v string) *string
- func StringInSlice(s string, slice []string) bool
- func StringToBool(s string) bool
- func StringToFloat32(s string) float32
- func StringToFloat64(s string) float64
- func StringToInt(s string) int
- func StringToInt16(s string) int16
- func StringToInt32(s string) int32
- func StringToInt64(s string) int64
- func StringToInt8(s string) int8
- func StructToMap(obj interface{}) map[string]interface{}
- func StructToMapIgnoreEmpty(obj interface{}) map[string]interface{}
- func StructToMapOmitEmpty(obj interface{}) (result map[string]interface{}, err error)
- func StructToMapString(obj interface{}) (map[string]string, error)
- func StructToMapStringOmitEmpty(obj interface{}) (map[string]string, error)
- func StructToPHPTransform(obj interface{}) interface{}
- func ToString(obj interface{}) string
- func Uint32CopyPtr(v uint32) *uint32
- func Uint64CopyPtr(v uint64) *uint64
- func Unescape(str string) (string, error)
- type BoolConverter
- type Float32Converter
- type Float64Converter
- type Int16Converter
- type Int32Converter
- type Int64Converter
- type Int8Converter
- type IntConverter
- type StringConverter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BoolCopyPtr ¶
func BoolToString ¶
func Float32CopyPtr ¶
func Float32ToString ¶
func Float64CopyPtr ¶
func Float64ToString ¶
func GetOrDefault ¶
func GetOrDefault(res interface{}, defaultValue interface{}) interface{}
func GetOrDefaultFloat64 ¶
func GetOrDefaultInt32 ¶
func GetOrDefaultInt64 ¶
func GetOrDefaultString ¶
func Int16CopyPtr ¶
func Int32CopyPtr ¶
func Int32ToString ¶
func Int64CopyPtr ¶
func Int64PtrCopyPtr ¶
func Int64ToString ¶
func Int8CopyPtr ¶
func IntCopyPtr ¶
func IntMeanToString ¶
IntMeanToString 特殊处理了0值的转换,主要是为了兼容某些下游的特殊需要,0值会转换为空字符串 其他逻辑,参考 IntToString
func IntToString ¶
IntToString int转换为string,比如1 => "1", 特别注意: 0 => "0"
func InterfaceToFloat64 ¶
func InterfaceToFloat64(inter interface{}) float64
func InterfaceToFloat64V2 ¶
InterfaceToFloat64V2 根据type assertion将interface转换成float
func InterfaceToInt ¶
func InterfaceToInt(inter interface{}) int
func InterfaceToInt64 ¶
func InterfaceToInt64(inter interface{}) int64
func InterfaceToJsonNum ¶
func InterfaceToString ¶
func InterfaceToString(inter interface{}) string
func JsonNumberToInt ¶
JsonNumberToInt 将json.Number解析为int,优先用Int64解析,其次试图将float64转换为int,都失败则返回错误
func MapFieldFormatToString ¶
func MapStringToStruct ¶
MapStringToStruct 将map[string]string转换为结构体 注意result传递的必须是指针,数据将直接解析到result里,请确保result的json tag配置正确
Example :
//原始数据 originalData:= map[string]string{ "name" : "bob", "age" : "100" } //所需结构体 type Person struct{ Name string `json:"name"` Age int `json:"age,string"` } //调用本方法进行解析 bob := &Person{} MapStringToStruct(originalData,bob) //output ,bob解析完毕: Bob(Person) { Name: "bob", Age : 100}
func PtrCopyBool ¶
func PtrCopyFloat32 ¶
func PtrCopyFloat64 ¶
func PtrCopyInt ¶
func PtrCopyInt16 ¶
func PtrCopyInt32 ¶
func PtrCopyInt64 ¶
func PtrCopyInt8 ¶
func PtrCopyString ¶
func PtrCopyUint32 ¶
func PtrCopyUint64 ¶
func SafeUnmarshal ¶
SafeUnmarshal 如果是数字,则会转化为jsonNumber
func StringCopyPtr ¶
func StringInSlice ¶
func StringToBool ¶
func StringToFloat32 ¶
func StringToFloat64 ¶
func StringToInt ¶
func StringToInt16 ¶
func StringToInt32 ¶
func StringToInt64 ¶
func StringToInt8 ¶
func StructToMap ¶
func StructToMap(obj interface{}) map[string]interface{}
func StructToMapIgnoreEmpty ¶
func StructToMapIgnoreEmpty(obj interface{}) map[string]interface{}
func StructToMapOmitEmpty ¶
func StructToMapString ¶
StructToMapString 将结构体转换为map[string]string
func StructToMapStringOmitEmpty ¶
StructToMapStringOmitEmpty 将结构体转换为map[string]string(有omitempty的情况)
func StructToPHPTransform ¶
func StructToPHPTransform(obj interface{}) interface{}
StructToPHPTransform 主要用途:按照php格式的结构体转换函数,主要用于json格式转换的兼容。 如果传入的是**结构体指针**不为空,那么返回结构体 如果传入的**结构体指针**是nil,那么返回空数组,用于json encode的时候,变成 "[]"
注意!! 入参必须是结构体指针,其他类型目前不支持,都将返回原本数据 Example: //创建一个结构体 testData = person{name: "bob", age: 20 } //传入结构体指针 result := StructToPHPTransform(&testData) //输出结果还是这个结构体指针 //output result = *person{name: "bob", age: 20} //但是如果传入一个空指针 result := StructToPHPTransform(nil) //返回值是一个空结构体数组,此时进行json encode,会变成[] //result = []struct{}
func Uint32CopyPtr ¶
func Uint64CopyPtr ¶
func Unescape ¶
Unescape 去除json字符串中的转义字符,尤其用于端上传来的某一个参数,是一个json字符串 Example:
//1.转义json,不带双引号,无法直接进行 json.Unmarshal, 所以需要进行反转义,返回值为: input := `{\"name\":\"suitingwei\",\"age\":13}` //进行反转义, output = {"name":"suitingwei","age":13} output,_ :=converter.Unescape(input) //2.转义json,带双引号 input := `"{\"name\":\"suitingwei\",\"age\":13}"` //进行反转义, output = {"name":"suitingwei","age":13} output,_ :=converter.Unescape(input) //3.不是转义的json,直接返回,主要是给一些IDL的 UnmarshalJSON方法提供便利,避免合法的json在这个函数调用后包凑 input := `{"name":"suitingwei","age":13}"` //进行反转义, output = {"name":"suitingwei","age":13} output,_ :=converter.Unescape(input)
注意:如果传入的不是转义后的字符串,会返回空
Types ¶
type BoolConverter ¶
type BoolConverter interface {
ToBool() bool
}
type Float32Converter ¶
type Float32Converter interface {
ToFloat32() float32
}
type Float64Converter ¶
type Float64Converter interface {
ToFloat64() float64
}
type Int16Converter ¶
type Int16Converter interface {
ToInt16() int16
}
type Int32Converter ¶
type Int32Converter interface {
ToInt32() int32
}
type Int64Converter ¶
type Int64Converter interface {
ToInt64() int64
}
type Int8Converter ¶
type Int8Converter interface {
ToInt8() int8
}
type IntConverter ¶
type IntConverter interface {
ToInt() int
}
type StringConverter ¶
type StringConverter interface {
ToString() string
}