utils

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FixedTime time.Time

Functions

func AssignValues

func AssignValues(command string, params map[string]string) string

Assign values to command parameters

func CreateFile

func CreateFile(file string) (*os.File, error)

CreateFile creates file.

func DefaultEnv

func DefaultEnv() map[string]string

DefaultEnv returns default value of environment variable.

func EscapeArg

func EscapeArg(input string, doubleQuotes bool) string

func EscapeSpecialchars

func EscapeSpecialchars(str string) string

func ExtractParamNames

func ExtractParamNames(command string) []string

extracts a slice of parameter names by removing the '$' from the command string.

func FileExists

func FileExists(file string) bool

FileExists returns true if file exists.

func FormatDuration

func FormatDuration(t time.Duration, defaultVal string) string

FormatDuration returns formatted duration.

func FormatTime

func FormatTime(t time.Time) string

FormatTime returns formatted time.

func LogErr

func LogErr(action string, err error)

LogErr logs error if it's not nil.

func MatchExtension

func MatchExtension(file string, exts []string) bool

MatchExtension returns true if extension matches.

func MustGetUserHomeDir

func MustGetUserHomeDir() string

MustGetUserHomeDir returns current working directory. Panics is os.UserHomeDir() returns error

func MustGetwd

func MustGetwd() string

MustGetwd returns current working directory. Panics is os.Getwd() returns error

func MustTempDir

func MustTempDir(pattern string) string

MustTempDir returns temporary directory.

func Now

func Now() time.Time

func OpenFile

func OpenFile(file string) (*os.File, error)

OpenFile opens file.

func OpenOrCreateFile

func OpenOrCreateFile(file string) (*os.File, error)

OpenOrCreateFile opens file or creates it if it doesn't exist.

func ParseCommand

func ParseCommand(value string) (string, error)

ParseCommand substitutes command in the value string.

func ParseTime

func ParseTime(val string) (time.Time, error)

ParseTime parses time string.

func ParseVariable

func ParseVariable(value string) (string, error)

ParseVariable parses variable string.

func RemoveParams

func RemoveParams(command string) string

Returns a command with parameters stripped from it.

func SplitCommand

func SplitCommand(cmd string, parse bool) (program string, args []string)

SplitCommand splits command string to program and arguments.

func StringWithFallback

func StringWithFallback(val, fallback string) string

StringsWithFallback returns the first non-empty string in the parameter list.

func StringifyParam

func StringifyParam(param Parameter) string

func TruncString

func TruncString(val string, max int) string

TrunString returns truncated string.

func UnescapeArg

func UnescapeArg(input string) (string, error)

func UnescapeSpecialchars

func UnescapeSpecialchars(str string) string

func ValidFilename

func ValidFilename(str, replacement string) string

ValidFilename returns true if filename is valid.

Types

type Parameter

type Parameter struct {
	Name  string
	Value string
}

func ParseParams

func ParseParams(input string, executeCommandSubstitution bool) ([]Parameter, error)

type SyncMap

type SyncMap struct {
	sync.Map
}

func (*SyncMap) MarshalJSON

func (m *SyncMap) MarshalJSON() ([]byte, error)

func (*SyncMap) UnmarshalJSON

func (m *SyncMap) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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