- Interface2Slice.
This commit is contained in:
@@ -124,6 +124,21 @@ func Interface2StringList(data interface{}) []string {
|
||||
return retVal
|
||||
}
|
||||
|
||||
func Interface2Slice(value interface{}) (retVal []interface{}) {
|
||||
typeInfo := reflect.TypeOf(value)
|
||||
if typeInfo.Kind() != reflect.Slice {
|
||||
panic("list must be slice type!")
|
||||
}
|
||||
if value != nil {
|
||||
valueInfo := reflect.ValueOf(value)
|
||||
retVal = make([]interface{}, valueInfo.Len())
|
||||
for i := 0; i < valueInfo.Len(); i++ {
|
||||
retVal[i] = valueInfo.Index(i).Interface()
|
||||
}
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
|
||||
func Slice2MapSlice(data []interface{}) []map[string]interface{} {
|
||||
retVal := make([]map[string]interface{}, len(data))
|
||||
for k, v := range data {
|
||||
|
||||
Reference in New Issue
Block a user