Golang converts unknown objects to arrays/array via reflection

Go converts unknown objects to arrays/array via reflection

func interfaceSlice(slice interface{}) []interface{} 
{ 
    s := reflect.ValueOf(slice)
    if s.Kind() != reflect.Slice {
        panic("InterfaceSlice() given a non-slice type")
    }
    ret := make([]interface{}, s.Len())
    for i := 0; i < s.Len(); i++ {
        ret[i] = s.Index(i).Interface()
    } 
    return ret
}

Comments

Popular posts from this blog

Python Receiving and parse JSON Data via UDP protocol

ubus lua client method and event registration code demo/example