GoVet警告说,该示例引用未知标识符,但为什么?
我有一个GoVet警告说,该示例引用未知标识符,但为什么?,go,Go,我有一个提取器界面,它有一个播放列表方法: // extractor.go package extractor type Extractor interface { Playlist(timestampFrom int64) (playlist.Tracklist, error) } 我正在另一个包中使用此接口: // fip.go package fip type Extractor struct { } func (extractor Extractor) Playlist(ti
提取器
界面,它有一个播放列表
方法:
// 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) {
// ...
}
在我的测试中,我想展示一个关于如何为fip
包使用Playlist
方法的示例:
// fip_test.go
package fip
func ExamplePlaylist() {
// ...
}
但是go-vet
显示此错误:
fip/extractor\u测试。go:82:1:ExamplePlaylist指未知标识符:Playlist
我不明白为什么<代码>播放列表作为一种方法存在于fip
包中。我错过了什么
如果需要更多上下文,请查看这些文件的完整源代码:
示例函数的正确名称为
示例提取器\u播放列表
,如测试文档的中所述
引述:
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
,示例函数的正确名称是examplextractor\u 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