utilities

package
v0.0.0-...-4aaa17f Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CmpMapValues

func CmpMapValues(map1, map2 map[string]string, key string) (int, error)

CmpMapValues is a helper function that compares a value shared by two maps / Input:

(map[string]string) map1 - First map to be compared
(map[string]string) map2 - Second map to be compared
(string) key - The key of the value be compared in both maps

Output:

(int) result - -1 for error, 0 for no difference, 1 for difference

func EqualArrays

func EqualArrays(arr1, arr2 []string) bool

EqualArrays determines if two string arrays are equal

func FileExists

func FileExists(path, desiredType string) int

FileExists determines if the path exists, and then if the path points to a file of the desired type Input:

(string) path - Local path to the file
(string) desiredType - The type of the file desired

Output: -1 if file doesn't exist, 0 if exists and is not desiredType, and 1 if file exists and is desiredType

func GcsDowndload

func GcsDowndload(bucket, object, destDir, name string, authenticate bool) (string, error)

GcsDowndload calls the GCS client api to download a specified object from a GCS bucket. Input:

(string) bucket - Name of the GCS bucket
(string) object - Name of the GCS object
(string) destDir - Destination for downloaded GCS object
(string) name - Name for the downloaded file
(bool) authenticate - Indicates whether the GCS client need to be authenticated.
                      Use unauthenticated client if you only wish to access public data.
                      Otherwise, ADC will be used for authorization.

Output:

(string) downloadedFile - Path to downloaded GCS object

func InArray

func InArray(val string, arr []string) bool

InArray determines if a string appears in a string array

func MountDisk

func MountDisk(diskFile, mountDir, partition string) (string, error)

MountDisk finds a free loop device and mounts a DOS/MBR disk file Input:

(string) diskFile - Name of DOS/MBR file (ex: disk.raw)
(string) mountDir - Mount Destination
(string) partition - The partition number you are pulling the offset from

Output:

(string) loopDevice - Name of the loop device used to mount

func ReadFileToMap

func ReadFileToMap(filePath, sep string) (map[string]string, error)

ReadFileToMap reads a text file line by line into a map. For each line key: first word split by separator, value: rest of line after separator. Ex: Inputs: textLine: "NAME=Container-Optimized OS", sep: "="

Outputs:  map: {"NAME":"Container-Optimized OS"}

Input:

(string) filePath - The command-line path to the text file
(string) sep - The separator string for the key and value pairs

Output:

(map[string]string) mapOfFile - The map of the read-in text file

func SliceToMapStr

func SliceToMapStr(input []string) map[string]string

SliceToMapStr initializes a map with keys from input and empty strings as values

func Unmount

func Unmount(mountedDirectory, loopDevice string) error

Unmount umounts a mounted directory and deletes its loop device

func WriteToNewFile

func WriteToNewFile(filename string, data string) error

WriteToNewFile creates a file and writes a string into it

Types

This section is empty.

Jump to

Keyboard shortcuts

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