pkg/platform: use const for OSType, improve GoDoc

It was not immediately clear why we were not using runtime.GOARCH for
these (with a conversion to other formats, such as x86_64). These docs
are based on comments that were posted when implementing this package;

- https://github.com/moby/moby/pull/13921#issuecomment-130106474
- https://github.com/moby/moby/pull/13921#issuecomment-140270124

Some links were now redirecting to a new location, so updated them to
not depend on the redirect.

While at it, also updated a call to logrus to use structured formatting
(WithError()).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-04-07 23:03:39 +02:00
parent 87019144f6
commit 790dd8cc92
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 18 additions and 10 deletions

View file

@ -8,18 +8,23 @@ import (
"github.com/sirupsen/logrus"
)
var (
// Architecture holds the runtime architecture of the process.
Architecture string
// OSType holds the runtime operating system type (Linux, …) of the process.
OSType string
)
// Architecture holds the runtime architecture of the process.
//
// Unlike [runtime.GOARCH] (which refers to the compiler platform),
// Architecture refers to the running platform.
//
// For example, Architecture reports "x86_64" as architecture, even
// when running a "linux/386" compiled binary on "linux/amd64" hardware.
var Architecture string
// OSType holds the runtime operating system type of the process. It is
// an alias for [runtime.GOOS].
const OSType = runtime.GOOS
func init() {
var err error
Architecture, err = runtimeArchitecture()
if err != nil {
logrus.Errorf("Could not read system architecture info: %v", err)
logrus.WithError(err).Error("Could not read system architecture info")
}
OSType = runtime.GOOS
}

View file

@ -13,7 +13,7 @@ var (
procGetSystemInfo = modkernel32.NewProc("GetSystemInfo")
)
// see http://msdn.microsoft.com/en-us/library/windows/desktop/ms724958(v=vs.85).aspx
// see https://learn.microsoft.com/en-gb/windows/win32/api/sysinfoapi/ns-sysinfoapi-system_info
type systeminfo struct {
wProcessorArchitecture uint16
wReserved uint16
@ -28,7 +28,10 @@ type systeminfo struct {
wProcessorRevision uint16
}
// Constants
// Windows processor architectures.
//
// see https://github.com/microsoft/go-winio/blob/v0.6.0/wim/wim.go#L48-L65
// see https://learn.microsoft.com/en-gb/windows/win32/api/sysinfoapi/ns-sysinfoapi-system_info
const (
ProcessorArchitecture64 = 9 // PROCESSOR_ARCHITECTURE_AMD64
ProcessorArchitectureIA64 = 6 // PROCESSOR_ARCHITECTURE_IA64