1 回答

TA貢獻1827條經驗 獲得超9個贊
您提供的代碼有點難以理解(不完整且目的不清楚),因此這里是一個簡化的示例,希望能夠回答您的問題。RequestHandlerProxy
請注意,從問題標題來看,我假設實現該接口的事實IAdapter
讓您感到困惑;這可能是無關緊要的(可能還有其他函數接受 an ,在其中傳遞 a或您自己的實現IAdapter
是有意義的,如下所示)。RequestHandlerProxy
IAdapter
adaptImpl
我已簡化IAdapter
為包含單個函數并將所有內容都放在一個文件中。要擴展它以在您的示例中工作,您將需要實現所有三個函數(Adapter_descriptor()
, Device_types()
& Health()
)。代碼可以在go Playground中運行(如果這不能回答您的問題,也許您可以修改該代碼以提供問題的簡化示例)。
package main
import "errors"
// IAdapter - Reduced to one function to make this simple
type IAdapter interface {
Adapter_descriptor() error
}
/// NewRequestHandlerProxy - Simplified version of the New function
func NewRequestHandlerProxy(iadapter IAdapter) {
return // code removed to make example simple
}
// adaptImpl - Implements the IAdapter interface
type adaptImpl struct {
isError bool // example only
}
// Adapter_descriptor - Implement the function specified in the interface
func (a adaptImpl) Adapter_descriptor() error {
if a.IsError {
return errors.New("An error happened")
}
return nil
}
func main() {
// Create an adaptImpl which implements IAdapter
x := adaptImpl{isError: true}
NewRequestHandlerProxy(x)
}
- 1 回答
- 0 關注
- 134 瀏覽
添加回答
舉報