osinfo

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2022 License: MIT Imports: 6 Imported by: 0

README

osinfo

Go library to detect OS information of the platform it is running on.

Install

go get github.com/Phuurl/osinfo

Supported operating systems

osinfo will return information about the following supported OSs:

  • Linux (kernel info for all, distro information required an /etc/os-release file)
  • macOS
  • Windows

Example

osinfo.GetOsInfo() returns an osinfo.Info struct, which looks like this when run on a Linux system (converted to JSON here for ease):

{
        "GOOS": "linux",
        "GOARCH": "arm64",
        "Details": {
                "Name": "Ubuntu",
                "Version": "20.04",
                "Build": "5.11.0-1028-aws"
        }
}

For more information on usage and the different returns for the different supported OSs, please see the GoDocs.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Details

type Details struct {
	Name    string
	Version string
	Build   string
}

Details contains the detected OS name and version information. macOS:

  • Name: OS name (eg `macOS` or `OSX`)
  • Version: OS version (eg `10.16`)
  • Build: OS build (eg `21C52`)

Linux:

  • Name: Distro name (eg `Ubuntu`)
  • Version: Distro release version (eg `20.04`)
  • Build: Linux kernel release (eg `5.11.0-1028-aws`)

Windows:

  • Name: Full OS name (eg `Windows 10 Pro`)
  • Version: OS major version (eg `10`)
  • Build: OS build (eg `21H1`)

type Info

type Info struct {
	GOOS    string
	GOARCH  string
	Details Details
}

Info contains standard GOOS and GOARCH info, and the more detailed Details struct

func GetOsInfo

func GetOsInfo() (Info, error)

GetOsInfo returns a populated Info struct with OS information, and an error object. Depending on the error encountered, if err != nil, the Info struct may still be partially populated.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL