adder_test.go
的测试文件来编写这些代码。%d
而不是 %s
作为格式字符串。这是因为我们希望打印一个整数而不是字符串。go test
运行测试./adder_test.go:6:9: undefined: Add
(x,y int)
而不是 (x int, y int)
。adder_test.go:10: expected '4' but got '0'
adder_test.go
文件添加以下 ExampleAdd 函数。adder_test.go
中缺少 import "fmt"
。无论你使用什么编辑器,都强烈建议你研究一下如何让编辑器自动处理这些错误。)godoc
的文档中,这将使你的代码更容易理解。godoc -http=:6060
并访问 http://localhost:6060/pkg/
。在这里你能看到 $GOPATH
下所有包的列表,假如你是在 $GOPATH/src/github.com/{your_id}
下编写的这些代码,你就能在文档中找到它。