utils

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Overview

file_util.go

gzip-util.go

misc-utis.go

os-util.go

string

text-util.go

time.go

tty-utils.go

Index

Constants

View Source
const (
	NONE = iota
	BLACK
	RED
	GREEN
	BLUE
	BROWN
	// YELLOW
	CYAN
	MAGENTA
	WHITE
)
View Source
const GZIP_SUFFIX = ".gz"
View Source
const STDERR uint = 2
View Source
const STDIN uint = 0
View Source
const STDOUT uint = 1

Variables

This section is empty.

Functions

func CreateGzipFile

func CreateGzipFile(in io.Reader, fileName string) (reader *bufio.Reader, err error)

func CreateGzipReader

func CreateGzipReader(in io.Reader) (reader *bufio.Reader, err error)

func EscapeShellSpecialChars

func EscapeShellSpecialChars(source string) string

func EscapeSpecialChars

func EscapeSpecialChars(source string, charSet string) string

func ExitErrorf

func ExitErrorf(rc int, format string, args ...interface{})

func ExitMessagef

func ExitMessagef(rc int, format string, args ...interface{})

func ExpandDirPathAndMakeParent

func ExpandDirPathAndMakeParent(specPath string) (expandedPath string, err error)

func ExpandFilePathAndMakeParent

func ExpandFilePathAndMakeParent(specPath string) (expandedPath, expandedParent string, err error)

func ExpandFilePathAndMakeParentV

func ExpandFilePathAndMakeParentV(specPath string, maps ...map[string]string) (expandedPath, expandedParent string, err error)

func ExpandPath

func ExpandPath(sourcePath string) (expandedPath string, err error)

func ExpandPathV

func ExpandPathV(sourcePath string, maps ...map[string]string) (expandedPath string, err error)

func ExpandRealPath

func ExpandRealPath(sourcePath string) (expandedRealPath string, err error)

func FileSize

func FileSize(filePath string) (size int64)

func GetProgramDirPath

func GetProgramDirPath() (dir string, err error)

func GetProgramPath

func GetProgramPath() (exec string, err error)

func IsDirectory

func IsDirectory(filePath string) bool

func IsRegularFile

func IsRegularFile(filePath string) bool
func IsSymLink(filePath string) bool

func IsSymLinkByDirEntry

func IsSymLinkByDirEntry(e os.DirEntry) bool

func JoinMap

func JoinMap(m map[string]any, kvSep, itemSep string) string

func JoinStringMap

func JoinStringMap(m map[string]string, kvSep, itemSep string) string

func MakeDir

func MakeDir(dirPath string) (err error)

func MakeParentDir

func MakeParentDir(filePath string) (dir string, err error)

func MoveFile

func MoveFile(sourcePath, destPath string) (int64, error)

* Ispirata a https://stackoverflow.com/a/50741908

func NewEnglishPrinter

func NewEnglishPrinter() *message.Printer

func OnCond

func OnCond(cond bool, trueValue, falseValue string) string

func OnCondIface

func OnCondIface(cond bool, trueValue, falseValue interface{}) interface{}

func OnCondInt

func OnCondInt(cond bool, trueValue, falseValue int) int

func OnCondInt64

func OnCondInt64(cond bool, trueValue, falseValue int64) int64

func OnEmpty

func OnEmpty(s string, altValues ...string) (value string)

func OnOk

func OnOk(cond bool) string

func OnStringIndex

func OnStringIndex(index uint, values ...string) (value string)

func OnSuccess

func OnSuccess(cond bool) string

func PadStringRight

func PadStringRight(s string, pad string, size int, suffix string) (paddedString string)

func ParseMemSize

func ParseMemSize(s string) (size int64, err error)

func ParseParamPairs

func ParseParamPairs(source io.Reader, separator string, hook func(line int, name, value string) (err error)) (err error)

func ParseParamPairsFile

func ParseParamPairsFile(sourceFile string, separator string, hook func(line int, name, value string) (err error)) (err error)

func ParseTimeInterval

func ParseTimeInterval(spec string, defaultUnit byte) (interval int64, err error)

Convert the spec string to a number of seconds. spec is a number, optionally followed by a time unit among 's'(seconds), 'm'(minutes), 'h'(hours), and 'd'(days) If the time unit is omitted, defaultUnit is used. Empty spec returns 0 seconds.

func RandBool

func RandBool() bool

func RemoveQuotes

func RemoveQuotes(s string) string

func S2Int32

func S2Int32(s string, defaultValue int32) int32

func S2Uint32

func S2Uint32(s string, defaultValue uint32) uint32

func ScopedSplitByRune

func ScopedSplitByRune(s string, sep rune, scopeOpeners, scopeClosers string, maxParts int) (parts []string)

func SplitByRune

func SplitByRune(s string, sep rune, maxParts int) (parts []string)

func SplitPair

func SplitPair(source, sep string) (left, right string)

func StartsWith

func StartsWith(s string, aliases ...string) bool

func StreamIsTerminal

func StreamIsTerminal(fh *os.File) bool

func StringSeconds2GoDuration

func StringSeconds2GoDuration(s string) (secs time.Duration)

func StringTimestamp2GoTime

func StringTimestamp2GoTime(s string) (ts time.Time)

func UnescapeBlanks

func UnescapeBlanks(source string) string

func UnescapeSpecialChars

func UnescapeSpecialChars(source string, charSet, specialChars string) string

Types

type TTYContext

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

func (*TTYContext) BlackFg

func (self *TTYContext) BlackFg(fd uint) string

func (*TTYContext) BlueFg

func (self *TTYContext) BlueFg(fd uint) string

func (*TTYContext) Bold

func (self *TTYContext) Bold(fd uint) string

func (*TTYContext) BoldOff

func (self *TTYContext) BoldOff(fd uint) string

func (*TTYContext) BrownFg

func (self *TTYContext) BrownFg(fd uint) string

func (*TTYContext) Clean

func (self *TTYContext) Clean()

func (*TTYContext) CyanFg

func (self *TTYContext) CyanFg(fd uint) string

func (*TTYContext) FgColor

func (self *TTYContext) FgColor(fd uint, n uint) string

func (*TTYContext) GreenFg

func (self *TTYContext) GreenFg(fd uint) string

func (*TTYContext) Init

func (self *TTYContext) Init()

func (*TTYContext) IsTTY

func (self *TTYContext) IsTTY(fd uint) bool

func (*TTYContext) Italic

func (self *TTYContext) Italic(fd uint) string

func (*TTYContext) ItalicOff

func (self *TTYContext) ItalicOff(fd uint) string

func (*TTYContext) MagentaFg

func (self *TTYContext) MagentaFg(fd uint) string

func (*TTYContext) RedFg

func (self *TTYContext) RedFg(fd uint) string

func (*TTYContext) Reset

func (self *TTYContext) Reset(fd uint) string

func (*TTYContext) Underline

func (self *TTYContext) Underline(fd uint) string

func (*TTYContext) UnderlineOff

func (self *TTYContext) UnderlineOff(fd uint) string

func (*TTYContext) WhiteFg

func (self *TTYContext) WhiteFg(fd uint) string

type TextTemplate

type TextTemplate struct {
	UserName   string
	Uid        string
	ProgramDir string
	HomeDir    string
	// contains filtered or unexported fields
}

func NewTextTemplate

func NewTextTemplate(args ...string) (instance *TextTemplate)

func (*TextTemplate) AddVar

func (self *TextTemplate) AddVar(name, value string)

func (*TextTemplate) Expand

func (self *TextTemplate) Expand(template string) string

func (*TextTemplate) ExpandEnv

func (self *TextTemplate) ExpandEnv(template string) (result string)

func (*TextTemplate) String

func (self *TextTemplate) String() string

func (*TextTemplate) Value

func (self *TextTemplate) Value(key string) (value string, ok bool)

Jump to

Keyboard shortcuts

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