osinfo
v1.0.5
This package provides a cross-platform way to identify the hardware your go code is running on.
The following fields are provided by the OSInfo struct:
| Field | Description |
|---|---|
| Family | The OS type as defined by GOOS |
| Architecture | The architecture as defined by GOARCH |
| ID | The OS ID as defined by the OS |
| Name | The OS name as defined by the OS |
| Codename | The release codename (if any) |
| Version | The release version |
| Build | The build number (if any) |
The following operating systems are currently supported:
If you wish to see another operating system supported (provided it is in
this list),
please open a pull request with the necessary changes and tests.
Use one of the existing getOSInfoXYZ() functions as a guide (most commonly
it involves parsing the output from a command or file).
info, err := osinfo.GetOSInfo()
if err != nil {
// TODO: Handle this
}
fmt.Printf("Family: %vn", info.Family)
fmt.Printf("Architecture: %vn", info.Architecture)
fmt.Printf("ID: %vn", info.ID)
fmt.Printf("Name: %vn", info.Name)
fmt.Printf("Codename: %vn", info.Codename)
fmt.Printf("Version: %vn", info.Version)
fmt.Printf("Build: %vn", info.Build)Family: linux
Architecture: amd64
ID: ubuntu
Name: Ubuntu
Codename: eoan
Version: 19.10
Build:
Family: linux
Architecture: amd64
ID: alpine
Name: Alpine Linux
Codename:
Version: 3.8.0
Build:
Family: windows
Architecture: amd64
ID: windows
Name: Windows 10 Pro
Codename: 1903
Version: 10.0
Build: 18362
Family: freebsd
Architecture: amd64
ID: freebsd
Name: FreeBSD
Codename:
Version: 12.0-RELEASE
Build: r341666
Family: darwin
Architecture: amd64
ID: darwin
Name: Mac OS X
Codename: Sierra
Version: 10.12.6
Build: 16G2136