I have the following simplified set of structs
type S0 struct {
UUID uuid.UUID
F00 int
F01 int
}
type S1 struct {
S0
F10 int
F11 int
}
type S2 struct {
S0
F20 int
}
<...>
type SN struct {
S0
FN0 int
<...>
FNM int
}
A struct S0 is equal to another struct S0 if all their fields(UUID, F0i) are equal. The struct Sk (k=1..N) is equal to the struct Sk, if their parts Sk.S0 are equal, even if all their fields Fki are not equal. But if their parts Sk.S0 are not equal, then structs will still be equal, if all their fields Fki are equal. Struct S0 is equal to any other struct Sk if Sk.S0 == S0. The struct Si is never equal to the struct Sj (i != j), even if Si.S0 == Sj.S0(In theory, this is generally unrealistic in current architecture, but just in case). All structs implement a common interface I.
I want to write the following equality function using go-cmp.
func EqualI(i1 I, i2 I) bool
I wrote the following comparison functions for each struct, which looks about the same, but how to combine them into one function EqualI and not get an error 'ambiguous set of applicable options'?
func EqualS0(s0_a S0, s0_b S0) bool {
return cmp.Equal(s0_a, s0_b)
}
func EqualS1(s1_a S1, s1_b S1) bool {
if EqualS0(s1_a.S0, s1_b.S0) {
return true
}
return cmp.Equal(s1_a, s1_b, cmpopts.IgnoreFields(S1{}, "S0.UUID", "S0.F00", "S0.F01"))
}
