Documentation ¶
Index ¶
- Constants
- func AppendUniqueCapSlice[T comparable](s []T, cap int, els ...T) (ns []T)
- func BytesSize(size float64) string
- func BytesSizeAround(size float64) string
- func Cd(dir string) (cwd string, err error)
- func Chunks(s string, chunkSize int) []string
- func ContextWithCancelSign(ctx context.Context, sign <-chan struct{}) (context.Context, context.CancelFunc)
- func CustomSize(format string, size float64, base float64, _map []string) string
- func DownloadTgFileToLocal(ctx context.Context, tgtoken string, tgFileId string, filepath string) error
- func Filter[T any](ss []T, test func(T) bool) (ret []T)
- func FindLineDataByFirstField(lines []string, index string) string
- func FromHumanSize(size string) (int64, error)
- func HumanSize(size float64) string
- func HumanSizeWithPrecision(size float64, precision int) string
- func RAMInBytes(size string) (int64, error)
- func RunCommand(cmd string, args ...string) (result string, err error)
- func SliceLastIndex[T comparable](s []T, v T) int
- func SliceLastIndexFunc[T comparable](s []T, test func(T) bool) int
- func SplitFirstAndOthers(str string) (first string, others string)
- func UniqueSlice[T comparable](s []T, except *T) (list []T)
- func UniqueSliceInLastOrder[T comparable](s []T, except *T) (list []T)
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func AppendUniqueCapSlice ¶
func AppendUniqueCapSlice[T comparable](s []T, cap int, els ...T) (ns []T)
Append els to s, then return the last cap unique elements of result
func BytesSize ¶
BytesSize returns a human-readable size in bytes, kibibytes, mebibytes, gibibytes, or tebibytes (e.g.: "44kiB", "17MiB").
func BytesSizeAround ¶
return at most 4 bytes, e.g.: "123G"
func Cd ¶
Change cwd to dir and return the new cwd. Try to parse real path of dir using system shell, so env expression can be used in dir. If dir is empty, use user home dir instead.
func Chunks ¶
Split s to slice of string. Eath string in result slice has at most chunkSize UTF-8 characters. From https://stackoverflow.com/questions/25686109/split-string-by-length-in-golang
func ContextWithCancelSign ¶
func ContextWithCancelSign(ctx context.Context, sign <-chan struct{}) (context.Context, context.CancelFunc)
return a ctx that is automatcally cancelled if sign received a data
func CustomSize ¶
CustomSize returns a human-readable approximation of a size using custom format.
func DownloadTgFileToLocal ¶
func DownloadTgFileToLocal(ctx context.Context, tgtoken string, tgFileId string, filepath string) error
downloading file from url, then send it to telegram bot
func FindLineDataByFirstField ¶
Each line in "no data" format, find the first line which no equals index and return it's data
func FromHumanSize ¶
FromHumanSize returns an integer from a human-readable specification of a size using SI standard (e.g.: "44kB", "17MB").
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 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.
func RunCommand ¶
Run a cmd and return combined output. If args is not provided, treat cmd as a cmdline and parse it to extract cmd args
func SliceLastIndex ¶
func SliceLastIndex[T comparable](s []T, v T) int
func SliceLastIndexFunc ¶
func SliceLastIndexFunc[T comparable](s []T, test func(T) bool) int
func SplitFirstAndOthers ¶
split str at first space character, return first and others part, both TrimSpaced
func UniqueSlice ¶
func UniqueSlice[T comparable](s []T, except *T) (list []T)
func UniqueSliceInLastOrder ¶
func UniqueSliceInLastOrder[T comparable](s []T, except *T) (list []T)
Types ¶
This section is empty.