我使用了github.com/hooklift/gowsdl/soap,并使用这种模式生成了代码
package funky
import (
"fmt"
)
type Place struct {
Text string
}
type RandomFunky interface {
Buggy(b int)(int)
}
type randomFunky struct {
place *Place
}
func NewFunky(p *Place) RandomFunky {
return &randomFunky{
place: p,
}
return nil
}
func (rf * randomFunky) Buggy(b int)(int) {
fmt.Println(rf.place.Text)
return b
}
package main
import (
"fmt"
"funky"
)
func main() {
p := funky.Place{}
p.Text = "o jee"
f := funky.NewFunky(&p)
fmt.Printf("%T\n",f) // type of "*funky.randomFunky"
// var f *funky.randomFunky !!! cannot refer to unexported name funky.randomFunky
f.Buggy(1)
}
“ f”-我可以这种方式获得这种类型,但是我不能创建这种类型的var!
因此,在您的情况下,RandomFunky
是具有单个方法Buggy
的全局接口,而randomFunky
是实现RandomFunky
的局部结构,因为它具有具有相同参数的方法Buggy
。
实际上,NewFunky
返回给您包装在接口中的结构。因此,不能在包randomFunky
之外使用funky
,但可以使用funky.RandomFunky
。
根据您的情况,您可以只创建这种类型的变量
...
var f funky.RandomFunky
f = funky.NewFunky(&p)
...