如何讓Golang示例可玩?如何在可玩的Godoc中包含示例
我有下面的代碼:
func Example_authenticate() {
fmt.Println("hello")
// Output: JSON
}
我需要的地方增加可玩的代碼來得到這個文件?
如何讓Golang示例可玩?如何在可玩的Godoc中包含示例
我有下面的代碼:
func Example_authenticate() {
fmt.Println("hello")
// Output: JSON
}
我需要的地方增加可玩的代碼來得到這個文件?
你必須與-play
標誌運行godoc
:
$ godoc --help
..........
-play=false: enable playground in web interface
例如運行godoc -http=:9020 -play
然後去http://localhost:9020/pkg/encoding/json/#example_Unmarshal
要安裝godoc
本地:
go get code.google.com/p/go.tools/cmd/godoc
這是主Godoc.org,但我希望我自己的包godoc玩。這可能嗎? – 2014-10-09 11:21:45
@PassionateDeveloper它取決於運行本地版本的操場,所以你必須運行你自己的本地godoc服務器並啓用操場。 – OneOfOne 2014-10-09 11:29:50
在當地godoc你的意思或godoc.org? – OneOfOne 2014-10-09 11:09:23
否爲我的包生成'godoc' – 2014-10-09 11:10:13