I'm new to Golang, My question is how to make function accept generic type of parameter. Here is the specific problem I met recently:
I defined a struct which contains a function
type TestArgs struct {
name string
...
customAssertForTypeA func(array []*pb.TypeA)
customAssertForTypeB func(array []*pb.TypeB)
}
// Define the test case with TestArgs.
tests := []TestArgs{
{
name: "Test A",
customAssertForTypeA: func(array []*pb.TypeA) {
// Some code
}
},
{
name: "Test B",
customAssertForTypeB: func(array []*pb.TypeB) {
// Some code
}
},
}
My question is how to make customerAssert function accept generic type of parameter?
I saw some similar question with solution interface{}, so I tried
customAssert func(array interface{})
and it doesn't work.