osversion.go 703 B

1234567891011121314151617181920212223242526272829303132333435
  1. //go:build !windows
  2. package buildinfo
  3. import (
  4. "strings"
  5. "github.com/shirou/gopsutil/v3/host"
  6. )
  7. // GetOSVersion returns OS version, kernel and bitness
  8. func GetOSVersion() (osVersion, osKernel string) {
  9. if platform, _, version, err := host.PlatformInformation(); err == nil && platform != "" {
  10. osVersion = platform
  11. if version != "" {
  12. osVersion += " " + version
  13. }
  14. }
  15. if version, err := host.KernelVersion(); err == nil && version != "" {
  16. osKernel = version
  17. }
  18. if arch, err := host.KernelArch(); err == nil && arch != "" {
  19. if strings.HasSuffix(arch, "64") && osVersion != "" {
  20. osVersion += " (64 bit)"
  21. }
  22. if osKernel != "" {
  23. osKernel += " (" + arch + ")"
  24. }
  25. }
  26. return
  27. }