假设我必须实现在两个不同的包中声明的两个不同的接口(在两个不同的分离项目中).
我有包裹 A
package A
type interface Doer {
Do() string
}
func FuncA(Doer doer) {
// Do some logic here using doer.Do() result
// The Doer interface that doer should implement,
// is the A.Doer
}
Run Code Online (Sandbox Code Playgroud)
并在包中 B
package B
type interface Doer {
Do() string
}
function FuncB(Doer doer) {
// some logic using doer.Do() result
// The Doer interface that doer should implement,
// is the B.Doer
}
Run Code Online (Sandbox Code Playgroud)
在我的main包裹中
package main
import (
"path/to/A"
"path/to/B" …Run Code Online (Sandbox Code Playgroud)