Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/imjasonh/osversion
https://github.com/imjasonh/osversion
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/imjasonh/osversion
- Owner: imjasonh
- License: apache-2.0
- Created: 2022-02-15T15:57:21.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-02-15T16:18:49.000Z (almost 3 years ago)
- Last Synced: 2024-10-14T16:51:20.254Z (3 months ago)
- Language: Go
- Size: 8.79 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `osversion`
[![e2e test](https://github.com/imjasonh/osversion/actions/workflows/e2e.yaml/badge.svg)](https://github.com/imjasonh/osversion/actions/workflows/e2e.yaml)
This repo contains a minimal library for detecting the current Windows version at runtime.
It's based on [similar code in Kubernetes](https://github.com/kubernetes/kubernetes/blob/30a21e9abdbbeb78d2b7ce59a79e46299ced2742/pkg/kubelet/winstats/version.go#L34-L76), itself seemingly based on [this StackOverflow answer](https://stackoverflow.com/questions/44363911/detect-windows-version-in-go), 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`](https://pkg.go.dev/golang.org/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](./.github/workflows/e2e.yaml) to see expected values for different Windows versions.