Problem
我已经在*_test.go文件中编写了一些示例函数,以帮助澄清独立公共函数的上下文,而不会出现问题.在为绑定到类型的函数编写示例函数时,会出现显示问题.
Example
这是我所遇到的一个基本例子.
假设我们在Main中有一个函数.如下所示:
type Client struct {
user string
ip string
}
func (c *Client) SendNotification(message string) error {
return nil
}
我想在main_test.go中为这样的函数创建一个示例函数,如下所示
func ExampleSendNotification() {
//Showoff code here
}
VSCode为该特定示例抛出错误,指出"ExampleSendNotify引用未知的标识符:SendNotification".此外,在运行godoc时,它也不会出现在示例中.
我也try 过这种形式:
func (c *Client) ExampleSendNotification() {
//Showoff code here
}
但随后它只是将其作为VSCode中的一个测试删除,并且不会出现