util

package
v4.6.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertArrayOfIntToString

func ConvertArrayOfIntToString(lun_ids []int32) string

ConvertArrayOfIntToString converts a given list of integer to comma separated string value

func CopyFile

func CopyFile(src, dst string) (err error)

CopyFile copies a file from src to dst. If src and dst files exist, and are the same, then return success. Otherise, attempt to create a hard link between the two files. If that fail, copy the file contents from src to dst.

func CreateDirIfNotExists

func CreateDirIfNotExists(dirPath string, perm os.FileMode) error

CreateDirIfNotExists to create a directory if it is not already available

func DecodeBase64Credential

func DecodeBase64Credential(b64data string) (string, error)

DecodeBase64Credential to plain text if its b64 encoded, else return the data as-is.

func ExecCommandOutput

func ExecCommandOutput(cmd string, args []string) (string, int, error)

ExecCommandOutput returns stdout and stderr in a single string, the return code, and error. If the return code is not zero, error will not be nil. Stdout and Stderr are dumped to the log at the debug level. Return code of 999 indicates an error starting the command.

func ExecCommandOutputWithStdinArgs

func ExecCommandOutputWithStdinArgs(cmd string, args []string, stdInArgs []string) (string, int, error)

ExecCommandOutputWithStdinArgs returns stdout and stderr in a single string, the return code, and error. If the return code is not zero, error will not be nil. Stdout and Stderr are dumped to the log at the debug level. Return code of 999 indicates an error starting the command.

func ExecCommandOutputWithTimeout

func ExecCommandOutputWithTimeout(cmd string, args []string, timeout int) (string, int, error)

ExecCommandOutputWithTimeout executes ExecCommandOutput with the specified timeout

func FileCheck

func FileCheck(e error)

FileCheck : checks for error

func FileDelete

func FileDelete(path string) error

FileDelete : delete the file

func FileExists

func FileExists(path string) (exists bool, dir bool, err error)

FileExists does a stat on the path and returns true if it exists In addition, dir returns true if the path is a directory

func FileGetStrings

func FileGetStrings(path string) (line []string, err error)

FileGetStrings : get the file contents as array of string

func FileGetStringsWithPattern

func FileGetStringsWithPattern(path string, pattern string) (filelines []string, err error)

FileGetStringsWithPattern : get the filecontents as array of string matching pattern pattern

func FileReadFirstLine

func FileReadFirstLine(path string) (line string, er error)

FileReadFirstLine read first line from a file TODO: make it OS independent

func FileSaveGob

func FileSaveGob(path string, object interface{}) error

FileSaveGob : save the Gob file

func FileWriteString

func FileWriteString(path, line string) (err error)

FileWriteString : write line to the path

func FileWriteStrings

func FileWriteStrings(path string, lines []string) (err error)

FileWriteStrings writes all lines to file specified by path. Newline is appended to each line

func FileloadGob

func FileloadGob(path string, object interface{}) error

FileloadGob : Load and Decode Gob file

func FindStringSubmatchMap

func FindStringSubmatchMap(s string, r *regexp.Regexp) map[string]string

FindStringSubmatchMap : find and build the map of named groups

func GetMD5HashOfTwoStrings

func GetMD5HashOfTwoStrings(string1, string2 string) string

func GetNltHome

func GetNltHome() (installDir string)

GetNltHome returns base install directory of NLT or HPE cloud toolkits

func GetSecondaryArrayDiscoveryIps

func GetSecondaryArrayDiscoveryIps(details string) []string

func GetSecondaryArrayLUNIds

func GetSecondaryArrayLUNIds(details string) []int32

func GetSecondaryArrayTargetNames

func GetSecondaryArrayTargetNames(details string) []string

func GetSecondaryBackends

func GetSecondaryBackends(details string) []*model.SecondaryLunInfo

func GetVolumeObject

func GetVolumeObject(serialNumber, lunID string) *model.Volume

func InitializeRouter

func InitializeRouter(router *mux.Router, routes []Route) (err error)

InitializeRouter initializes all handlers

func IsFileSymlink(path string) (exists bool, symlink bool, err error)

IsFileSymlink to check if the path exists and if it's a symlink

func ToCamelCase

func ToCamelCase(str string) string

ToCamelCase converts the given snake_case string to camelCase

func ToSnakeCase

func ToSnakeCase(str string) string

ToSnakeCase converts the given camelCase string into snake_case

Types

type FileWatch

type FileWatch struct {
	// contains filtered or unexported fields
}

FileWatch contains watcher attributes.

func InitializeWatcher

func InitializeWatcher(job func()) (*FileWatch, error)

InitializeWatcher is used to initialize fileWatch with anonymous function and new watcher. It regularly monitors os signals like SIGTERM,SIGHUP etc in a separate thread for graceful exit of the watcher.

func (*FileWatch) AddWatchList

func (w *FileWatch) AddWatchList(files []string) error

AddWatchList list of files /and directories to watch

func (*FileWatch) StartWatcher

func (w *FileWatch) StartWatcher()

StartWatcher triggers watcher until os sig interrupt. This will run anonymous fn forever.

type Route

type Route struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
}

Route struct

Jump to

Keyboard shortcuts

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