Documentation
¶
Index ¶
- Constants
- func Assign(dst any, src any, excludeFieldIndexes []int)
- func BytesSize(size float64) string
- func BytesSizeAround(size float64) string
- func CleanBasename(name string) string
- func CleanBasenameComponent(name string) string
- func CleanFileBasename(name string) string
- func CleanFilePath(p string) string
- func CleanPath(p string) string
- func CountNonZeroVariables(vars ...any) (cnt int)
- func CustomSize(format string, size float64, base float64, _map []string) string
- func DomSelectionText(s *goquery.Selection) string
- func ExistsFileWithAnySuffix(name string, suffixes ...string) string
- func FileExists(name string) bool
- func FilterSlice[T any](ss []T, test func(T) bool) (ret []T)
- func First[T any](t T, args ...any) T
- func FirstNonZeroArg[T comparable](args ...T) T
- func FormatDate(t int64) string
- func FormatTime(t int64) string
- func FromHumanSize(size string) (int64, error)
- func GetExtFromType(typ string) string
- func GetFunctionName(i any) string
- func HumanSize(size float64) string
- func HumanSizeWithPrecision(size float64, precision int) string
- func LogAzureHttpRequest(req *azuretls.Request)
- func LogAzureHttpResponse(res *azuretls.Response, err error)
- func LookPathWithSelfDir(name string) (string, error)
- func MakeCleanTmpDir(tmpdir string) error
- func Map[T1 any, T2 any](ss []T1, mapper func(T1) T2) (ret []T2)
- func Md5(input string) string
- func OmitemptySlice[T comparable](slice []T) (list []T)
- func ParseInt[T constraints.Integer](s string, defaultValue T) T
- func PrintJson(output io.Writer, value any) error
- func RAMInBytes(size string) (int64, error)
- func Sleep(seconds int)
- func SplitCsv(str string) []string
- func UniqueSlice[T comparable](slice []T) (list []T)
- func UnmarshalJson[T any](source []byte) (T, error)
- func Unwrap[T any](t T, err error) T
- func Xlsx2Csv(xlsxFile string) error
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func Assign ¶
https://stackoverflow.com/questions/23350173 copy non-empty field values from src to dst. dst and src must be pointors of same type of plain struct
func BytesSize ¶
BytesSize returns a human-readable size in bytes, kibibytes, mebibytes, gibibytes, or tebibytes (e.g. "44kiB", "17MiB").
func BytesSizeAround ¶
Return at most 6 chars, e.g. "123.1G". It removes trailing zero(s) and dot, e.g. "123.0GiB" => "123G".
func CleanBasename ¶
Return a cleaned safe base filename (without path). 1. CleanBaseFilenameComponent. 2. Clean trailing dot (".") (Windows does NOT allow dot in the end of filename) 3. TrimSpace 4. Truncate name to at most 240 (UTF-8 string) bytes.
func CleanBasenameComponent ¶
Return a cleaned safe base filename component. 1. Replace invalid chars with alternatives (e.g. "?" => "?"). 2. CleanTitle (clean \r, \n and other invisiable chars then TrimSpace).
func CleanFileBasename ¶
Similar to CleanBaseName, but treats name as a filename (base+ext) and tries to preserve ext. It also removes spaces between base and ext.
func CleanFilePath ¶
Similar to CleanPath but treat p as a file path (the basename of p contains ext), and try to preserve ext in basename.
func CleanPath ¶
Clean & normaliza & sanitize p path. 1. path.Clean. 2. Replace \ with / . 3. Clean each part of the path, replace invalid chars with alternatives, truncate too long names.
func CountNonZeroVariables ¶
Return count of variable in vars that fulfil the condition that variable is non-zero value
func CustomSize ¶
CustomSize returns a human-readable approximation of a size using custom format.
func DomSelectionText ¶
Return deduplicated and combined text of dom elements. That is, if both parent and child node are in the same selection, it will only write once of parent's content to result, ignoring the (duplicate) child node. It will Clean result.
func ExistsFileWithAnySuffix ¶
Check whether a file (or dir) with name + <any suffix in list> exists in file system. If exists, return name + suffix. Else, return empty string. If len(suffixes) == 0, return name if itself exists.
func FileExists ¶
Check whether a file (or dir) with name exists in file system
func FilterSlice ¶
Return filtered ss. The ret is nil if and only if ss is nil.
func FirstNonZeroArg ¶
func FirstNonZeroArg[T comparable](args ...T) T
func FormatDate ¶
func FormatTime ¶
func FromHumanSize ¶
FromHumanSize returns an integer from a human-readable specification of a size using SI standard (e.g. "44kB", "17MB").
func GetFunctionName ¶
func HumanSize ¶
HumanSize returns a human-readable approximation of a size capped at 4 valid numbers (e.g. "2.746 MB", "796 KB").
func HumanSizeWithPrecision ¶
HumanSizeWithPrecision allows the size to be in any precision, instead of 4 digit precision used in units.HumanSize.
func LogAzureHttpRequest ¶
func LogAzureHttpRequest(req *azuretls.Request)
Log if dump-headers flag is set.
func LogAzureHttpResponse ¶
func LogAzureHttpResponse(res *azuretls.Response, err error)
Log if dump-headers flag is set.
func LookPathWithSelfDir ¶
Similar to exec.LookPath, but also look up for dir of self executable file.
func MakeCleanTmpDir ¶
Make a new empty temp dir at tmpdir location. If tmpdir already exists, clean it first(remove itself with all contents inside it).
func OmitemptySlice ¶
func OmitemptySlice[T comparable](slice []T) (list []T)
func ParseInt ¶
func ParseInt[T constraints.Integer](s string, defaultValue T) T
func RAMInBytes ¶
RAMInBytes parses a human-readable string representing an amount of RAM in bytes, kibibytes, mebibytes, gibibytes, or tebibytes and returns the number of bytes, or -1 if the string is unparseable. Units are case-insensitive, and the 'b' suffix is optional. Specially, if size is "-1", return -1,nil
func UniqueSlice ¶
func UniqueSlice[T comparable](slice []T) (list []T)
func UnmarshalJson ¶
Unmarshal source as json of type T
func Xlsx2Csv ¶
Convert "abc.xlsx" to "abc.xlsx.csv". Adopted from https://github.com/shenwei356/csvtk/blob/master/csvtk/cmd/xlsx2csv.go .
Types ¶
This section is empty.