I have 15 custom types in this application, and the processing I wish to do to them is actually very generic to them all.
In each case, I need to iterate over a slice of whatever type it is that I am working with.
an interface is what currently gets passed, but it certainly doesn't have to remain that way
I have the following code :
func ProcessSlice(in interface{}){
switch reflect.TypeOf(p.in).Kind() {
case reflect.Slice:
s := reflect.ValueOf(p.in)
for i := 0; i < s.Len(); i++ {
fmt.Println(reflect.ValueOf(p.in))
}
}
}
the fmt.Println is there for debugging, and I get the following sort of output :
[map[_Id:4K7qx_mUSbV-----------== name:<name ommited> _class:basic_organization] map[_Id:4K7qx_mUnvB-----------== name:<name omitted> _class:basic_organization]]
My real question here, is let's say I have the types :
MyCustomStructA,
MyCustomeStructB
and I bail into that function with a slice of either, how can I end up in that loop, working with actual struct items? Because at the minute, I wind up with a map, and that is not what I want here.