duandian8251 2018-09-25 12:38
浏览 93
已采纳

如何访问平台特定的软件包文档?

We can access Go's package documentation online on the official website:

https://golang.org/pkg/

This only contains the package documentation available on the linux platform (GOOS), amd64 archicture (GOARCH).

Or offline via the go doc command, e.g package doc of the syscall package.

go doc syscall

This shows documentation for the platform of the Go SDK.

Some packages have different API based on the platform we target, most famous is the syscall package.

How can we access platform specific package documentation online and offline?

  • 写回答

1条回答 默认 最新

  • 普通网友 2018-09-25 12:38
    关注

    1. Online

    Online, platform specific documentation can be accessed on the official Go home page, by appending the GOOS and GOARCH query parameters, similar to the environment variables.

    For example, to access the syscall package documentation for Windows 64-bit platform, visit:

    https://golang.org/pkg/syscall/?GOOS=windows&GOACH=amd64

    To quickly verify that it works, search for the type DLL phrase (or simply DLL), as those don't appear on linux's syscall package.

    2. Offline

    The go tool has default target platform and architecture which can be overridden with the GOOS and GOARCH environment variables. So by default go doc syscall will show package documentation for the default platform and architecture.

    To get doc for other platforms and / or architectures, all we need to do is change those environment variables.

    On unix systems (e.g. linux, OS-X), we can simply prepend the go doc command with the new platform / architecture we're interested in, e.g. package doc of syscall for Windows (executed on Linux):

    GOOS=windows go doc syscall
    

    And that's all it takes. To quickly check if it works, print the DLL type and its methods:

    GOOS=windows go doc syscall DLL
    

    Example output:

    type DLL struct {
        Name   string
        Handle Handle
    }
        A DLL implements access to a single DLL.
    
    
    func MustLoadDLL(name string) *DLL
    func (d *DLL) FindProc(name string) (proc *Proc, err error)
    func (d *DLL) MustFindProc(name string) *Proc
    func (d *DLL) Release() (err error)
    

    This is documented in the syscall package:

    The details vary depending on the underlying system, and by default, godoc will display the syscall documentation for the current system. If you want godoc to display syscall documentation for another system, set $GOOS and $GOARCH to the desired system. For example, if you want to view documentation for freebsd/arm on linux/amd64, set $GOOS to freebsd and $GOARCH to arm.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?