utils

package module
v0.0.0-...-4ef91b1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TimeFactors = []struct {
	suffix string
	factor float64
}{
	{"ms", 0.001},
	{"s", 1},
	{"m", 60},
	{"h", 3600},
	{"d", 86400},
	{"w", 86400 * 7},
	{"y", 86400 * 365},
}

Functions

func ASCIITable

func ASCIITable(header []ASCIITableHeader, rows interface{}, escapePipes bool) (string, error)

ASCIITable creates an ascii table from columns and data rows

func CloneStringMap

func CloneStringMap(src map[string]string) (clone map[string]string)

func CopyFile

func CopyFile(src, dst string) error

Copy file from src to destination

func CopyFileMode

func CopyFileMode(src, dst string) error

Copy file modes from src to destination

func DurationString

func DurationString(dur time.Duration) string

func ExpandDuration

func ExpandDuration(val string) (res float64, err error)

ExpandDuration expand duration string into seconds

func FieldsFuncN

func FieldsFuncN(str string, fun func(rune) bool, maxV int) []string

FieldsFuncN is like strings.FieldsFunc, but returns at most n fields, and the nth field includes any runes at the end of the string normally excluded by f.

func FieldsN

func FieldsN(s string, n int) []string

FieldsN is like strings.Fields, but returns at most n fields, and the nth field includes any whitespace at the end of the string.

func GetExecutablePath

func GetExecutablePath() (execDir, execFile, execPath string, err error)

GetExecutablePath returns path to executable information execDir: folder of the executable execFile: file name (basename) of executable execPath: full path to executable (dir/file)

func GetSecureCiphers

func GetSecureCiphers() (ciphers []uint16)

func IsDigitsOnly

func IsDigitsOnly(s string) bool

IsDigitsOnly returns true if string only contains numbers

func IsFile

func IsFile(path string) error

IsFile returns an err if the path does not exist or is not a regular file

func IsFloatVal

func IsFloatVal(val interface{}) bool

IsFloatVal returns true if given val is a real float64 with fractions or false if value can be represented as int64

func IsFolder

func IsFolder(path string) error

IsFolder returns an err if the path does not exist or is not a folder

func LineCounter

func LineCounter(reader *os.File) int

Count lines in file

func List2String

func List2String(list []string) (res string)

List2String converts a list of strings into a single quoted comma separated list: 'a', 'b', 'c'...

func LogThreadDump

func LogThreadDump(log *factorlog.FactorLog)

func MimeType

func MimeType(fileName string) (mime string, err error)

func ParseTLSMinVersion

func ParseTLSMinVersion(version string) (uint16, error)

func ParseVersion

func ParseVersion(str string) (num float64)

func ReadPid

func ReadPid(pidfile string) (int, error)

func ReplaceCommonPasswordPattern

func ReplaceCommonPasswordPattern(str string) string

func Sha256FileSum

func Sha256FileSum(path string) (hash string, err error)

Sha256FileSum returns sha256 sum for given file

func Sha256Sum

func Sha256Sum(text string) (hash string, err error)

Sha256Sum returns sha256 sum for given string

func SortRanked

func SortRanked(list []string, ranks map[string]int) []string

func SortedKeys

func SortedKeys[V interface{}](m map[string]V) []string

returns string map keys in sorted order

func TimeUnitF

func TimeUnitF(num uint64, targetUnit string, precision int) float64

returns time/duration in target unit with given precision

func ToPrecision

func ToPrecision(val float64, precision int) float64

ToPrecision converts float64 to given precision, ex.: 5.12345 -> 5.1

func Tokenize

func Tokenize(str string) []string

Tokenize returns list of string tokens token will still have quotes around after tokenizing

func TokenizeBy

func TokenizeBy(str, separator string, keepQuotes, keepSeparator bool) []string

TokenizeBy returns list of string tokens separated by any char in separator

func TrimQuotes

func TrimQuotes(str string) (res string, err error)

Types

type ASCIITableHeader

type ASCIITableHeader struct {
	Name     string // name in table header
	Field    string // attribute name in data row
	Centered bool   // flag wether column is centered
	// contains filtered or unexported fields
}

type ByRank

type ByRank []WordRank

func (ByRank) Len

func (a ByRank) Len() int

func (ByRank) Less

func (a ByRank) Less(i, j int) bool

func (ByRank) Swap

func (a ByRank) Swap(i, j int)

type WordRank

type WordRank struct {
	Word string
	Rank int
}

WordRank is used to sort []string lists by ranked prefixes

Jump to

Keyboard shortcuts

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