[问题] Golang的interface

楼主: Nt1 (用功点吧!)   2018-01-12 18:52:37
小弟刚从Python转Golang,有些关念还不是很清楚,请大家指教一下。
我有一个 Interface,定义两个 method 如下:
type Content interface{
GetContent(filters map[string]string) (Content, error)
GetContents(filters map[string]string) ([]*Content, int64, error)
}
然后实做 struct 如下
type MyContent struct {
TypeA blablabla
TypeB blablabla
}
func (t *MyContent) GetContent(filters map[string]string) (
item Content, err error) {
item = &MyContent{}
// do something, 这个function 可以work
}
# 这个function可以work,可以透过实做 interface 来达到我想要的功能
func (t *MyContent) GetContents(filters map[string]string) (
items []*Content, total int64, err error) {
err = nil
items = []&MyContent{}
#^^^^^^^^^^^^^^^^^^^^^ 死在这行
#cannot use []MyContent literal (type []MyContent) as type []*Content in
#assignment
但第二个function一直出现错误,请问我该怎么解呢?感谢

Links booklink

Contact Us: admin [ a t ] ucptt.com