Hey @Deimis, do you mean like this, because type switches are pretty awesome:
package main
import "fmt"
type MyObjOne []struct {
id int
val int
}
type MyObjTwo []struct {
id int
val int
}
func OutputObject(obj interface{}) string {
var str string
switch o := obj.(type) {
case MyObjOne:
for _, mo1 := range o {
str += fmt.Sprintf("MyObjOne, id: %d, val %d\n", mo1.id, mo1.val)
}
case MyObjTwo:
for _, mo2 := range o {
str += fmt.Sprintf("MyObjTwo, id: %d, val %d\n", mo2.id, mo2.val)
}
}
return str
}
func main() {
m1 := MyObjOne{
{1, 2},
{3, 4},
}
m2 := MyObjTwo{
{5, 6},
{7, 8},
}
fmt.Println(OutputObject(m1))
fmt.Println(OutputObject(m2))
}