osinfo

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2023 License: MIT Imports: 7 Imported by: 11

README

OS Info

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)

Supported Operating Systems

The following operating systems are currently supported:

  • Linux
  • FreeBSD
  • macOS
  • Windows

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).

Usage

	info, err := osinfo.GetOSInfo()
	if err != nil {
		// TODO: Handle this
	}

	fmt.Printf("Family:       %v\n", info.Family)
	fmt.Printf("Architecture: %v\n", info.Architecture)
	fmt.Printf("ID:           %v\n", info.ID)
	fmt.Printf("Name:         %v\n", info.Name)
	fmt.Printf("Codename:     %v\n", info.Codename)
	fmt.Printf("Version:      %v\n", info.Version)
	fmt.Printf("Build:        %v\n", info.Build)
Output on various platforms
Ubuntu Linux
Family:       linux
Architecture: amd64
ID:           ubuntu
Name:         Ubuntu
Codename:     eoan
Version:      19.10
Build:
Alpine Linux
Family:       linux
Architecture: amd64
ID:           alpine
Name:         Alpine Linux
Codename:
Version:      3.8.0
Build:
Windows
Family:       windows
Architecture: amd64
ID:           windows
Name:         Windows 10 Pro
Codename:     1903
Version:      10.0
Build:        18362
FreeBSD
Family:       freebsd
Architecture: amd64
ID:           freebsd
Name:         FreeBSD
Codename:
Version:      12.0-RELEASE
Build:        r341666
Mac OS
Family:       darwin
Architecture: amd64
ID:           darwin
Name:         Mac OS X
Codename:     Sierra
Version:      10.12.6
Build:        16G2136

Documentation

Overview

Package osinfo provides a cross-platform way to identify the hardware your code is running on.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OSInfo

type OSInfo struct {
	Family       string
	Architecture string
	ID           string
	Name         string
	Codename     string
	Version      string
	Build        string
}

func GetOSInfo

func GetOSInfo() (*OSInfo, error)

GetOSInfo gets information about the current operating system. The OSInfo object will always be valid, even on error. If an error occurs, OSInfo will contain at least the Family and Architecture fields, with a good chance that Name will also contain something.

Jump to

Keyboard shortcuts

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