我開始用簡單的界面:實現接口方法與變量參數
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