osdetector

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2020 License: MIT Imports: 6 Imported by: 0

README

Go OS Detector Library

This library detects your OS Distribution version.

Usage

fs := afero.NewOsFs()
osd := osdetector.NewOsDetector(fs)
distro, err := osd.GetOSDistro(runtime.GOOS)
if err != nil {
		return err
}
log.Info("%s / %s / %s / %s / %s", distro.BasedOn, distro.Dist, distro.Os, distro.PseudoName, distro.Rev)

Known limitations

At the moment it can only detect only major Linux distributions.

Documentation

Index

Constants

View Source
const (
	UnknownDistr = "unknown"
	UnknownRev   = "unknown"
)
View Source
const (
	OsBasedOnRedHat      = "RedHat"
	OsBasedOnSuSe        = "SuSe"
	OsBasedOnMandrake    = "Mandrake"
	OsBasedOnDebian      = "Debian"
	OsBasedOnContainerOS = "ContainerOS"
)
View Source
const (
	OsNameLinux = "Linux"
)

Variables

View Source
var (
	REOSRedHatDist       = regexp.MustCompile(`(.*) release.*`)
	REOSRedHatPseudoName = regexp.MustCompile(`\((.*)\)$`)
	REOSRedHatRev        = regexp.MustCompile(`(?U).* release (.*)( \(.*\))?$`)

	REOSSuSePseudoName = regexp.MustCompile(`CODENAME = (.*)(\n|\z)`)
	REOSSuSeRev        = regexp.MustCompile(`VERSION = (.*)(\n|\z)`)

	REOSDebianOldDist       = regexp.MustCompile(`DISTRIB_ID=(.*)(\n|\z)`)
	REOSDebianOldRev        = regexp.MustCompile(`DISTRIB_RELEASE=(.*)(\n|\z)`)
	REOSDebianOldPseudoName = regexp.MustCompile(`DISTRIB_CODENAME=(.*)(\n|\z)`)

	REOSDebianRev = regexp.MustCompile(`^PRETTY_NAME="Debian GNU/Linux (\d+) \((.*)\)"$`)
)

Functions

This section is empty.

Types

type Distro

type Distro struct {
	Os         string
	BasedOn    string
	Dist       string
	PseudoName string
	Rev        string
}

type OsDetector

type OsDetector struct {
	// contains filtered or unexported fields
}

func NewOsDetector

func NewOsDetector(fs afero.Fs) *OsDetector

func (*OsDetector) GetDebianDistro

func (osd *OsDetector) GetDebianDistro() (*Distro, error)

func (*OsDetector) GetLinuxDistro

func (osd *OsDetector) GetLinuxDistro() (*Distro, error)

func (*OsDetector) GetOSDistro

func (osd *OsDetector) GetOSDistro(os string) (*Distro, error)

func (*OsDetector) GetOSFromOSRelease added in v1.1.0

func (osd *OsDetector) GetOSFromOSRelease() (*Distro, error)

func (*OsDetector) GetRedHatDistro

func (osd *OsDetector) GetRedHatDistro() (*Distro, error)

func (*OsDetector) GetSuSeDistro

func (osd *OsDetector) GetSuSeDistro() (*Distro, error)

func (*OsDetector) GetWindowsDistro added in v1.1.0

func (osd *OsDetector) GetWindowsDistro() (*Distro, error)

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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