如何在Godoc中包含可玩的示例 [英] How to include Example with playable in Godoc

查看:106
本文介绍了如何在Godoc中包含可玩的示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个下面的代码:

  func Example_authenticate(){
fmt.Println(hello)
//输出:JSON
}

我需要在Doc的某个位置添加可播放的代码才能在Doc中获得此代码吗?

解决方案您必须使用 -play 标志运行 godoc

  $ godoc  - 帮助
..........
-play = false:在网络界面中启用操场

例如,运行 godoc -http =:9020 -play 然后转到 http:// localhost:9020 / pkg / encoding / json /#example_Unmarshal



在本地安装 godoc

  go get code.google.com/p /go.tools/cmd/godoc 


How do you make Golang example playable?

I have a below code:

func Example_authenticate() {
    fmt.Println("hello")
    // Output: JSON
}

Do I need to add playable code somewhere to get this in Doc?

解决方案

You have to run godoc with the -play flag:

$ godoc --help
..........
  -play=false: enable playground in web interface

For example run godoc -http=:9020 -play then go to http://localhost:9020/pkg/encoding/json/#example_Unmarshal

To install godoc locally:

go get code.google.com/p/go.tools/cmd/godoc

这篇关于如何在Godoc中包含可玩的示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆