我想定义一个返回接口切片的处理程序类型,类似于以下示例:
package main
import "fmt"
type PersonInterface interface {
GetName() string
}
type Person struct {
Name string
}
func (person *Person) GetName() string {
return person.Name
}
type PersonGetter func() []Person
func pg() []*Person {
return []*Person{&Person{Name: "John Doe"}}
}
func main() {
var person PersonInterface
person = &Person{"John Doe"}
fmt.Println(person)
var personGetter PersonGetter
personGetter = pg
}
但是,如果我运行它,我会得到
cannot use pg (type func() []*Person) as type PersonGetter in assignment
我将如何定义一个返回接口切片的通用函数类型?(我已阅读https://github.com/golang/go/wiki/InterfaceSlice但我不确定如何在此处应用它)。