osrelease

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2021 License: BSD-3-Clause Imports: 5 Imported by: 59

README

osrelease Build Status

A Go package to make reading in os-release files easy.

See https://www.freedesktop.org/software/systemd/man/os-release.html

Installation

$ go get github.com/cobaugh/osrelease

Usage

See godoc

package main

import (
	"fmt"
	"github.com/cobaugh/osrelease"
)

func main() {
	// for reference, two variables are provided:
	fmt.Printf("EtcOsRelease = %v\n", osrelease.EtcOsRelease)
	fmt.Printf("UsrLibOsRelease = %v\n", osrelease.UsrLibOsRelease)

	// let osrelease find what file to load
	osrelease, err := osrelease.Read()
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
	fmt.Printf("PRETTY_NAME = %v\n", osrelease["PRETTY_NAME"])

	// specify the file to load explicitly
	osrelease, err = osrelease.ReadFile("/etc/os-release")
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
	fmt.Printf("PRETTY_NAME = %v\n", osrelease["PRETTY_NAME"])
}

Output:

$ ./examples 
EtcOsRelease = /etc/os-release
UsrLibOsRelease = /usr/lib/os-release
PRETTY_NAME = void
PRETTY_NAME = void```

Documentation

Overview

osrelease is a go package to make reading the contents of os-release files easier

See https://www.freedesktop.org/software/systemd/man/os-release.html

Index

Examples

Constants

View Source
const EtcOsRelease string = "/etc/os-release"
View Source
const UsrLibOsRelease string = "/usr/lib/os-release"

Variables

This section is empty.

Functions

func Read

func Read() (osrelease map[string]string, err error)

Read and return os-release, trying EtcOsRelease, followed by UsrLibOsRelease. err will contain an error message if neither file exists or failed to parse

Example
osrelease, err := Read()
if err != nil {
	fmt.Printf("Error: %v\n", err)
	return
}
fmt.Printf("PRETTY_NAME = %v\n", osrelease["PRETTY_NAME"])
Output:

func ReadFile

func ReadFile(filename string) (osrelease map[string]string, err error)

Similar to Read(), but takes the name of a file to load instead

Example
osrelease, err := ReadFile("/etc/os-release")
if err != nil {
	fmt.Printf("Error: %v\n", err)
	return
}
fmt.Printf("PRETTY_NAME = %v\n", osrelease["PRETTY_NAME"])
Output:

func ReadString

func ReadString(content string) (osrelease map[string]string, err error)

ReadString is similar to Read(), but takes a string to load instead

Types

This section is empty.

Jump to

Keyboard shortcuts

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