Browse Source

Merge branch 'master' of https://git.tetele.net/tgo/helper

master v0.2.9
yangzm 2 years ago
parent
commit
0d5aa7b020
1 changed files with 37 additions and 10 deletions
  1. +37
    -10
      map.go

+ 37
- 10
map.go View File

@ -97,32 +97,59 @@ func MapStringToInterface(src map[string]string) map[string]interface{} {
}
//将interface转成map[string]interface
func InterfaceToMapInterface(data interface{})(map[string]interface{},error){
dataJson,err := json.Marshal(data)
func InterfaceToMapInterface(data interface{}) (map[string]interface{}, error) {
dataJson, err := json.Marshal(data)
if err != nil {
return nil,err
return nil, err
}
var returnData map[string]interface{}
err = json.Unmarshal(dataJson,&returnData)
err = json.Unmarshal(dataJson, &returnData)
return returnData,nil
return returnData, nil
}
//将interface转成map[string]string
func InterfaceToMapString(data interface{}) (map[string]string, error) {
dataJson, err := json.Marshal(data)
if err != nil {
return nil, err
}
var returnData map[string]string
err = json.Unmarshal(dataJson, &returnData)
return returnData, nil
}
//将interface转成[]map[string]interface
func InterfaceToMapInterfaceArr(data interface{})([]map[string]interface{},error){
dataJson,err := json.Marshal(data)
func InterfaceToMapInterfaceArr(data interface{}) ([]map[string]interface{}, error) {
dataJson, err := json.Marshal(data)
if err != nil {
return nil,err
return nil, err
}
var returnData []map[string]interface{}
err = json.Unmarshal(dataJson,&returnData)
err = json.Unmarshal(dataJson, &returnData)
return returnData, nil
}
//将interface转成[]map[string]string
func InterfaceToMapStringArr(data interface{}) ([]map[string]string, error) {
dataJson, err := json.Marshal(data)
if err != nil {
return nil, err
}
var returnData []map[string]string
err = json.Unmarshal(dataJson, &returnData)
return returnData,nil
return returnData, nil
}
/**


Loading…
Cancel
Save