utils

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package utils contains various utility methods

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppDir added in v0.3.0

func AppDir(appName, userDefinedPath string) (string, error)

AppDir - returns application home folder where all files are stored. appName is application name which will be used as folder name. userDefinedPath allows you to set a custom path to application home folder, can be relative or absolute. If userDefinedPath is not empty, it will be used as application home folder Else, userConfigDir will be used, which is system dependent.

func BuildProcess added in v0.3.0

func BuildProcess(cmd string) *exec.Cmd

BuildProcess - builds exec.Cmd object from command string.

func BuildProcessInterceptStdAll added in v1.2.0

func BuildProcessInterceptStdAll(command string) *exec.Cmd

BuildProcessInterceptStdAll - builds a process where both stdout and stderr are intercepted for further processing.

func BuildProcessInterceptStdErr added in v1.2.0

func BuildProcessInterceptStdErr(command string) *exec.Cmd

BuildProcessInterceptStdErr - builds a process where stderr is intercepted for further processing.

func CheckAppRequirements added in v1.5.0

func CheckAppRequirements(appHome string) error

func ExtractBaseURL added in v1.5.0

func ExtractBaseURL(urlPath string) (string, error)

ExtractBaseURL extracts the base URL (scheme + host + port) from a URL by removing the path and query parameters. Example: "http://127.0.0.1:8080/path/to/resource" -> "http://127.0.0.1:8080"

func FetchFromURL added in v1.5.0

func FetchFromURL(urlPath string) (io.ReadCloser, error)

FetchFromURL fetches content from a URL and returns it as a string.

func FprintfIgnoreErrorf added in v1.5.0

func FprintfIgnoreErrorf(w io.Writer, format string, args ...any)

FprintfIgnoreErrorf - writes formatted string to the writer, ignoring any errors.

func IsFolderExists added in v1.5.0

func IsFolderExists(folderPath string) bool

func IsSupportedURL added in v1.5.0

func IsSupportedURL(path string) bool

IsSupportedURL checks if the given path is a URL starting with http, https, or ftp.

func LogAndCloseApp added in v1.5.0

func LogAndCloseApp(lg loggerInterface, exitCode int, exitReason string)

LogAndCloseApp logs the close message, closes the logger, and exits with the specified code.

func RemoveDuplicateSpaces added in v1.1.0

func RemoveDuplicateSpaces(arguments string) string

RemoveDuplicateSpaces - removes two or more spaces from the string.

func SSHConfigDefaultFilePath added in v1.5.0

func SSHConfigDefaultFilePath() (string, error)

SSHConfigDefaultFilePath - returns default ssh_config path or error.

func SSHConfigPath added in v1.5.0

func SSHConfigPath(userDefinedPath string) (string, error)

SSHConfigPath - returns ssh_config path or error.

func StringAbbreviation added in v1.3.0

func StringAbbreviation(s string) string

StringAbbreviation - creates an abbreviation from a string, combining starting letters from first and last words. For example:

"Alexandria, Egypt"      -> "AE"
"Babylon Iraq"           -> "BI"
"Carthage, North Africa" -> "CA"
"Thebes_Greece"          -> "TG"

func StringEmpty added in v0.4.0

func StringEmpty(s *string) bool

StringEmpty - checks if string is empty or contains only spaces. s is string to check.

func StripStyles added in v1.3.0

func StripStyles(input string) string

StripStyles - removes lipgloss styles from a string.

Types

type ProcessBufferWriter added in v1.1.0

type ProcessBufferWriter struct {
	Output []byte
}

ProcessBufferWriter - is an object which pretends to be a writer, however it saves all data into a temporary buffer variable for future reading and doesn't write anything in terminal. Utilized to parse process stdout or stderr.

func (*ProcessBufferWriter) Write added in v1.1.0

func (writer *ProcessBufferWriter) Write(p []byte) (int, error)

Write - doesn't write anything, it saves all data in err variable, which can ve read later.

Jump to

Keyboard shortcuts

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