Go Vet警告说,该示例是指未知标识符,但为什么呢?



我有一个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() { ... }

您的示例是TExtractorMPlaylist的最后一种情况。

最新更新