utils

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: Apache-2.0 Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DirExistAndHasContent

func DirExistAndHasContent(dirPath string) error

DirExistAndHasContent checks if the given directory exists and has content.

Parameters:

  • dirPath: The path to the directory to check.

Returns:

  • error: An error if the directory does not exist or if there is any other issue.

Example:

err := DirExistAndHasContent("/path/to/dir")
if err != nil {
    log.Fatalf("Error: %v", err)
} else {
    fmt.Println("The directory exists and has content.")

func FileHasContent

func FileHasContent(file string) error

FileHasContent checks if the specified file exists and has content.

Parameters:

  • file: The path to the file to check.

Returns:

  • error: An error if the file does not exist, is empty, or if there is any other issue.

Example:

err := FileHasContent("/path/to/file.txt")
if err != nil {
    log.Fatalf("Error: %v", err)
} else {
    fmt.Println("The file exists and has content.")

func GetAllEnvVarsFromHost

func GetAllEnvVarsFromHost() map[string]string

GetAllEnvVarsFromHost retrieves all environment variables from the host and returns them as a map.

Returns:

  • map[string]string: A map containing all environment variables from the host.

Example:

envVars := GetAllEnvVarsFromHost()
fmt.Printf("Host environment variables: %v\n", envVars)

func IsValidDirE

func IsValidDirE(path string) error

IsValidDirE checks if the given path is a valid directory.

Parameters:

  • path: The path to check.

Returns:

  • error: An error if the path is not a valid directory.

Example:

err := IsValidDirE("/path/to/check")
if err != nil {
    log.Fatalf("Error: %v", err)
} else {
    fmt.Println("The path is a valid directory.")

func MergeSlices added in v0.0.8

func MergeSlices(slices ...[]string) []string

MergeSlices merges multiple slices of strings into a single slice.

Parameters:

  • slices: Variadic parameter representing multiple slices of strings to be merged.

Returns:

  • []string: A single slice containing all the elements from the input slices.

Example:

slice1 := []string{"a", "b"}
slice2 := []string{"c", "d"}
merged := MergeSlices(slice1, slice2)
fmt.Printf("Merged slice: %v\n", merged)

Types

type EnvVar

type EnvVar struct {
	Name  string
	Value string
}

EnvVar represents an environment variable with a name and value.

func GetAllEnvVarsFromHostAsStruct

func GetAllEnvVarsFromHostAsStruct(envVarNames []string) []EnvVar

GetAllEnvVarsFromHostAsStruct retrieves the specified environment variables from the host and returns them as a slice of EnvVar structs.

Parameters:

  • envVarNames: A list of environment variable names to retrieve.

Returns:

  • []EnvVar: A slice of EnvVar structs representing the specified environment variables.

Example:

envVarNames := []string{"PATH", "HOME"}
envVars := GetAllEnvVarsFromHostAsStruct(envVarNames)
fmt.Printf("Host environment variables as structs: %v\n", envVars)

Jump to

Keyboard shortcuts

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