假设我有一个接口:
type Module interface {
Run(moduleInput x) error // x is the type of moduleInput
}
每个“模块”都将实现Run功能。然而,这moduleInput不是一个单一的结构——它应该能够接受任何结构但只允许结构,即不是interface{}(比如,只有moduleAInputs和moduleBInputs结构)。
理想情况下Run,每个模块的函数都具有moduleXInputX 是示例模块的类型。
moduleInput是否可以使用泛型或其他方式来限制类型?
呼啦一阵风
相关分类