Golang电线掉线:x类型未实现接口错误

时间:2019-06-05 20:27:11

标签: go

以下是示例代码,其中大部分是从官方golang文档Locator Strategies复制而来的 我只添加了最后一段代码,该代码为使用Fooer接口的类型生成实例。

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException

但是,出现以下错误

 type Fooer interface {
        Foo() string
}

type MyFooer string

func (b *MyFooer) Foo() string {
    return string(*b)
}

func provideMyFooer() *MyFooer {
    b := new(MyFooer)
    *b = "Hello, World!"
    return b
}

type Bar string

func provideBar(f Fooer) string {
    // f will be a *MyFooer.
    return f.Foo()
}

type test struct {
    f Fooer 
}
var Set = wire.NewSet(
    provideMyFooer,
    wire.Bind(new(Fooer), new(*MyFooer)),
    provideBar)
// InitializeMasterRepo init repo
func testbuild() test  {
    wire.Build(
        Set)
    return test{}
}

1 个答案:

答案 0 :(得分:0)

类型错误。您的收件人是*MyFooer;您的值为(如错误所示)**MyFooer。这是因为您正在呼叫new(*MyFooer)new已经返回了指向所传递类型的指针,因此,由于您将指针类型传递给它,因此您将获得指向该指针的指针。

按如下所示更改该行以解决此错误:

wire.Bind(new(Fooer), new(MyFooer))
相关问题