util

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DateConversion

func DateConversion(data string) (string, error)

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

func GetHostname() (string, error)

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

func GetMachineId() (string, error)

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 SplitPackageName

func SplitPackageName(package_name string) (name, version, release, epoch, arch string)

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

This section is empty.

Jump to

Keyboard shortcuts

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