问题
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:
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.
来源:https://stackoverflow.com/questions/52498435/how-to-access-platform-specific-package-documentation