【发布时间】:2015-10-13 23:52:35
【问题描述】:
我从简单的界面开始:
type Module interface {
Init(deps ...interface{}) error
}
我想,实现会非常简单,因为这个方法应该匹配任意数量的提供的参数。这就是我最终得到这段代码的结果,我想,TestModule 实现了Module 接口。
type TestModule struct {
}
func (m *TestModule) Init(str string) error {
return nil
}
但是当我想将 TestModule 传递给任何需要 Module 的函数时,我得到了这个错误:
不能在 testFunc 的参数中使用模块(类型 *TestModule)作为类型模块:
func testFunc(module Module) {
}
编辑:是否有实现这种行为的最佳实践?
【问题讨论】: