我开始用简单的界面:实现接口方法与变量参数
type Module interface {
Init(deps ...interface{}) error
}
我以为,实施将是非常简单的,因为这种方法应该匹配任意数量的提供的参数。这就是我用这个代码结束的想法,TestModule
实现了Module
接口。
type TestModule struct {
}
func (m *TestModule) Init(str string) error {
return nil
}
但是,当我想将TestModule传递给希望模块的所有功能,我得到这个错误:
cannot use module(type *TestModule) as type Module in argument to testFunc:
func testFunc(module Module) {
}
编辑:有没有实施这种行为的任何最佳实践?
我编辑了帖子。感谢您的快速回复。 – Gelidus
@Gelidus我不能帮上忙,但我给了你我的两分钱。 – evanmcdonnal