You can use reflection ( reflect) to check if the pointer type matters.
func firstPointerIdx(s []interface{}) int {
for i, v := range s {
if reflect.ValueOf(v).Kind() == reflect.Ptr {
return i
}
}
return -1
}
Note that the code above checks the type of value that is "wrapped" in interface{}(this is the type of the element of the sslice parameter ). This means that if you pass a snippet like this:
s := []interface{}{"2", nil, (*string)(nil)}
2, nil, - ( nil).