Documentation
¶
Overview ¶
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. More about the os-release: https://www.linux.org/docs/man5/os-release.html
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Path = "/etc/os-release"
Path contains the default path to the os-release file
Functions ¶
func DateConversion ¶
DateConversion takes a date string input and converts it to RFC3339 format. It attempts to parse the input date string using multiple common date formats and returns the formatted date as a string.
Parameters:
- data: A string representing a date in any common format
Returns:
- string: The date formatted in RFC3339 format (2006-01-02T15:04:05Z07:00)
- error: An error if the date parsing fails, nil otherwise
func GetHostname ¶
GetHostname retrieves the hostname of the system by reading the /etc/hostname file. It returns the hostname as a string and any error encountered during the process. The hostname is trimmed of leading/trailing whitespace before being returned. If the file cannot be read, it returns an empty string and an error with details.
func GetMachineId ¶
GetMachineId retrieves the unique machine identifier from the '/etc/machine-id' file. This identifier is typically used to distinguish the host machine in a network.
Returns:
- string: The machine ID as a trimmed string
- error: An error if reading the machine-id file fails
func PackageBinary ¶
func PackageBinary() string
PackageBinary determines and verifies the appropriate package manager binary (yum or dnf) based on the Linux distribution version. It reads /etc/os-release to check if the system is running RHEL/CentOS 8 or 9, in which case it selects 'dnf' instead of the default 'yum'.
The function also verifies if the selected package manager is installed in the system. If the binary is not found, it exits with an error message.
Returns:
- string: The name of the package manager binary ("yum" or "dnf")
The function will exit with status code 1 if the required package manager is not installed.
func ParseOSRelease ¶ added in v1.2.0
func ParseOSRelease() error
ParseOSRelease parses the os-release file pointing to by Path. The fields are saved into the Release global variable.
func SplitPackageName ¶
SplitPackageName splits a RPM package name into its components. It takes a package name string as input and returns the following components:
- name: The name of the package
- version: The version number
- release: The release number
- epoch: The epoch number (empty string if not present)
- arch: The architecture
The function expects package names in the following format: [name]-[version]-[release].[arch].rpm or [name]-[epoch]:[version]-[release].[arch].rpm
The .rpm suffix is optional and will be trimmed if present. If epoch is not present in the package name, an empty string is returned for that component.
Types ¶
type OSRelease ¶ added in v1.2.0
type OSRelease struct {
Name string
Version string
ID string
IDLike string
PrettyName string
VersionID string
HomeURL string
DocumentationURL string
SupportURL string
BugReportURL string
PrivacyPolicyURL string
VersionCodename string
UbuntuCodename string
ANSIColor string
CPEName string
BuildID string
Variant string
VariantID string
Logo string
}
var Release OSRelease