Skip to content

Instantly share code, notes, and snippets.

@whiledoing
Created March 21, 2020 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whiledoing/da47c6f5657593438efea64e0d83bc3a to your computer and use it in GitHub Desktop.
Save whiledoing/da47c6f5657593438efea64e0d83bc3a to your computer and use it in GitHub Desktop.
// 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