我有一个Extractor
有Playlist
方法的接口:
// extractor.go
package extractor
type Extractor interface {
Playlist(timestampFrom int64) (playlist.Tracklist, error)
}
Run Code Online (Sandbox Code Playgroud)
我在另一个包中使用这个接口:
// fip.go
package fip
type Extractor struct {
}
func (extractor Extractor) Playlist(timestampFrom int64) ([]playlist.Track, error) {
// ...
}
Run Code Online (Sandbox Code Playgroud)
在我的测试中,我想展示一个有关如何使用Playlist
该fip
包的方法的示例:
// fip_test.go
package fip
func ExamplePlaylist() {
// ...
}
Run Code Online (Sandbox Code Playgroud)
但go vet
显示此错误:
fip/extractor_test.go:82:1: ExamplePlaylist refers to unknown identifier: Playlist
我不明白为什么...Playlist
确实作为包中的方法存在fip
。我缺少什么?
如果需要更多上下文,请参阅以下文件及其完整源代码:
https://github.com/coaxis/tizinger/blob/8016d52a1278cf44dde13d518c6a15a18cb29774/fip/fip.go
https://github.com/coaxis/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() { ... }
Run Code Online (Sandbox Code Playgroud)
您的示例是最后一种情况,其中T
isExtractor
和M
is Playlist
。