osversion

This repo contains a minimal library for detecting the current Windows version at runtime.
It's based on similar code in Kubernetes, itself seemingly based on this StackOverflow answer, without requiring the large dependency on Kubernetes, and with end-to-end tests using GitHub Actions.
It has a single dependency on x/sys/windows/registry
.
Its intended use is to be able to match OCI container image manifests with a platform value that specifies an os.version
, so that the correct image can be selected, taking into account the Windows OS version.
Usage
import "github.com/imjasonh/osversion"
...
fmt.Printf("The current osversion is %q", osversion.Get())
...
When this package is used on Windows, osversion.Get
returns a string like "10.0.17763"
, depending on the current Windows version.
If this package is used on any non-Windows OS, osversion.Get
returns an empty string.
See end-to-end test config to see expected values for different Windows versions.