我有一个Extractor
接口,它有一个Playlist
方法:
// extractor.go
package extractor
type Extractor interface {
Playlist(timestampFrom int64) (playlist.Tracklist, error)
}
我在另一个包中使用此接口:
// fip.go
package fip
type Extractor struct {
}
func (extractor Extractor) Playlist(timestampFrom int64) ([]playlist.Track, error) {
// ...
}
在我的测试中,我想展示一个关于如何将Playlist
方法用于fip
包的示例:
// fip_test.go
package fip
func ExamplePlaylist() {
// ...
}
但是go vet
显示此错误:fip/extractor_test.go:82:1: ExamplePlaylist refers to unknown identifier: Playlist
我不明白为什么...Playlist
确实作为fip
包中的方法存在。我错过了什么?
如果需要更多上下文,请参阅包含完整源代码的以下文件:
https://github.com/coaxial/tizinger/blob/8016d52a1278cf44dde13d518c6a15a18cb29774/extractor/extractor.go
https://github.com/coaxial/tizinger/blob/8016d52a1278cf44dde13d518c6a15a18cb29774/fip/fip.go
https://github.com/coaxial/tizinger/blob/8016d52a1278cf44dde13d518c6a15a18cb29774/fip/fip_test.go
示例函数的正确名称ExampleExtractor_Playlist
,如测试文档的示例部分所述。
引用:
The naming convention to declare examples for the package, a function F, a type T and method M on type T are:
func Example() { ... }
func ExampleF() { ... }
func ExampleT() { ... }
func ExampleT_M() { ... }
您的示例是T
Extractor
而M
Playlist
的最后一种情况。