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 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b