Created
March 21, 2020 12:28
-
-
Save whiledoing/da47c6f5657593438efea64e0d83bc3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from: https://stackoverflow.com/questions/12753805/type-converting-slices-of-interfaces | |
// make any slice to interface{} slice | |
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment