osinfo

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: MIT Imports: 7 Imported by: 0

README

Go SysPkg: OSInfo

Go SysPkg is a library that provides system package management and operating system information. This documentation focuses on the osinfo package, which allows you to obtain information about the operating system.

Installation

To install the github.com/bluet/syspkg/osinfo package, use the following command:

go get github.com/bluet/syspkg/osinfo

Usage

To use the osinfo package, you need to import it into your Go program:

import (
 "github.com/bluet/syspkg/osinfo"
)
GetOSInfo

The primary function in the osinfo package is GetOSInfo(). It returns an *OSInfo struct, which contains information about the operating system, including:

  • Name
  • Distribution
  • Version
  • Architecture

Here's an example of how to use the GetOSInfo() function:

package main

import (
 "fmt"
 "github.com/bluet/syspkg/osinfo"
)

func main() {
 osInfo, err := osinfo.GetOSInfo()
 if err != nil {
  fmt.Println("Error getting OS info:", err)
  return
 }

 fmt.Println("Name:", osInfo.Name)
 fmt.Println("Distribution:", osInfo.Distribution)
 fmt.Println("Version:", osInfo.Version)
 fmt.Println("Architecture:", osInfo.Arch)
}

In this example, the GetOSInfo() function is called, and the returned *OSInfo struct is used to print information about the operating system. If there is an error, it is handled and displayed to the user.

Run the example with the following command:

go run main.go

You should see output similar to the following:

Name: linux
Distribution: Ubuntu
Version: 20.04
Architecture: amd64

The output will vary depending on the system you are running the program on.

Summary

The osinfo package of the Go SysPkg library provides a simple and efficient way to obtain information about the operating system. The GetOSInfo() function is easy to use and returns a struct containing all the necessary information about the system's OS. This package can be useful for programs that need to detect the OS and perform tasks specific to a particular OS, distribution, or version.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OSInfo

type OSInfo struct {
	Name         string
	Distribution string
	Version      string
	Arch         string
}

OSInfo represents the operating system information, including its name, distribution, version, and architecture.

func GetOSInfo

func GetOSInfo() (*OSInfo, error)

GetOSInfo returns the OS information, as a pointer to an OSInfo struct. The OSInfo struct contains the following fields:

  • Name: OS name (ex, linux, darwin, windows)
  • Distribution: OS distribution (ex, Ubuntu)
  • Version: OS version (ex, 20.04)
  • Arch: OS architecture (ex, amd64)
Example

ExampleGetOSInfo demonstrates how to use the GetOSInfo function to obtain information about the operating system.

package main

import (
	"fmt"

	"github.com/bluet/syspkg/osinfo"
)

func main() {
	osInfo, err := osinfo.GetOSInfo()
	if err != nil {
		fmt.Println("Error getting OS info:", err)
		return
	}

	fmt.Println("Name:", osInfo.Name)
	fmt.Println("Distribution:", osInfo.Distribution)
	fmt.Println("Version:", osInfo.Version)
	fmt.Println("Architecture:", osInfo.Arch)
}

Jump to

Keyboard shortcuts

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