douhuan2101 2013-07-30 10:54
浏览 55
已采纳

您如何查看特定go功能的文档?

I'm looking for a convenient way to quickly look up the documentation for different functions and/or packages in Go. My current approach is to google for say ioutil.ReadFile, but that is pretty slow/inconvenient. The ideal solution would work directly in vim or maybe in a Go interpreter(suggestions?).

E.g. in Python the documentation of a function can be shown in PyDev by hovering over a function or using the ipython interpreter with e.g. os.open? or help(os.open).

How do you view specific documentation for Go?

  • 写回答

4条回答 默认 最新

  • dongwen5336 2013-07-30 11:18
    关注

    You have many possibilities:

    • Browse http://golang.org/pkg/ and/or use the "Search" box, which even knows regexps!
    • Run local godoc and get the same for all locally installed packages. Faster and off-line!
    • Query godoc from the command line:

    $ godoc io/ioutil ReadFile
    PACKAGE DOCUMENTATION
    
    package ioutil
        import "io/ioutil"
    
    
    
    FUNCTIONS
    
    func ReadFile(filename string) ([]byte, error)
        ReadFile reads the file named by filename and returns the contents. A
        successful call returns err == nil, not err == EOF. Because ReadFile
        reads the whole file, it does not treat an EOF from Read as an error to
        be reported.
    
    
    $ 
    

    • Use Rob Pike's doc[0].

    $ doc ioutil.ReadFile
    http://golang.org/pkg/io/ioutil/#ReadFile
    /home/jnml/go/src/pkg/io/ioutil/ioutil.go:48:
    // ReadFile reads the file named by filename and returns the contents.
    // A successful call returns err == nil, not err == EOF. Because ReadFile
    // reads the whole file, it does not treat an EOF from Read as an error
    // to be reported.
    func ReadFile(filename string) ([]byte, error)
    
    $ 
    

    [0]: $ go get code.google.com/p/rspace.cmd/doc

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备