The fact that you are indexing a slice is unsafe - if it is empty, you will get panic in standby mode out of range. Regardless, this is not necessarily due to the package reflects the Elem() method :
type Type interface { ... // Elem returns a type element type. // It panics if the type Kind is not Array, Chan, Map, Ptr, or Slice. Elem() Type ... }
So here is what you want to use:
func GetTypeArray(arr interface{}) reflect.Type { return reflect.TypeOf(arr).Elem() }
Please note that in accordance with the change of @tomwilde, the arr argument can be of any type at all, so there is nothing stopping you from passing a GetTypeArray() unsharp value at runtime and getting a panic.
source share