Categorygithub.com/coghost/xutil
modulepackage
0.1.2-20240111
Repository: https://github.com/coghost/xutil.git
Documentation: pkg.go.dev

# README

xutil

utils for golang but for personal use only

# Packages

No description provided by the author

# Functions

A2B convert any types to byte.
No description provided by the author
AnyJoin: join all args with sep, even value in args is zero if you don't want zero values, use `AnyJoinNon0` instead.
AnyJoinNon0: all zero valid will be skipped but " " is allowed.
AnyJoinNon0ToUpper @return string.ToUpper.
AorB returns the first non zero value.
ArrA2B convert interface array to byte array.
ArrB2A convert byte array to interface array.
ArrB2S convert byte array to string.
ArrS2B convert string array to byte array.
B2A convert byte to other type.
No description provided by the author
No description provided by the author
No description provided by the author
Caller wraps runtime.Caller and returns file and line number information Returns: filename, linenum.
No description provided by the author
CatchPanicAsErr try fn with recover, return the panic as error.
CeilInt: @return int(Ceil(a / b)).
No description provided by the author
CharToNum: substract `number+Chars` from source str returns int by default.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
DefaultIfNil checks if the value is nil, if true returns the default value otherwise the original.
No description provided by the author
DiffRate @return float(a-b) / b.
DummyErrorLog will print a dummy log with red bg Deprecated: use xpretty.DummyErrorLog instead.
DummyLog will print a dummy log with green bg Deprecated: use xpretty.DummyLog instead.
No description provided by the author
DumpCallerStack print the caller tree.
Duration usage: `xutil.Duration(xutil.Track("doing sth"))`.
No description provided by the author
No description provided by the author
EnsureByRetry Params: - fn - args: tries, delay, showLogOrNot wrapper of retry.Do with default - total try 3 times - overwritten by args[0] - WARN: if args[0] == 0, the "fn" will be skipped - if args[0] < 0, will use default 3 - retry delay of 0 millisecond - overwritten by args[1] - on retry not print logs - overwritten by args[2].
No description provided by the author
No description provided by the author
No description provided by the author
FirstNonNil returns the first non nil parameter.
FirstNonZero returns the first non zero values, and if all are zero vlaues, return the first value in args.
FirstOrDefaultArgs return the first args value, if args not empty else return default value.
No description provided by the author
No description provided by the author
GetAttr beware `o` should be the pointer.
GetCharNumOr returns parsed number or keep original.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
GetIntByIndex index can be less than 0.
No description provided by the author
GetLocalIpAddr @return ip:port.
No description provided by the author
GetStrByIndex index can be less than 0.
GetStrBySplit: split raw str with separator and join from offset example: raw = "a,b,c,d,e" v, b := GetStrBySplit(raw, ",", 1) // v = "bcde", b = true v, b := GetStrBySplit(raw, "_", 1) // v = "a,b,c,d,e", b = false v, b := GetStrBySplit(raw, ",", -1) // v = "e", b = false @return string @return bool.
GetStrBySplitAtIndex split raw to slice and then return element at index - if sep not in raw, returns raw - if index < 0, reset index to len() + index - if index > total length, returns the last one - else returns element at index.
No description provided by the author
No description provided by the author
No description provided by the author
IfThen evaluates a condition, if true returns the parameters otherwise nil.
IfThenElse evaluates a condition, if true returns the first parameter otherwise the second.
IfThenElse evaluates a condition, if true returns the first parameter otherwise the second.
InitializeXOpts setups - debug: used in `PauseToDebug` - recover: used in `RecoverAndDumpOnly` - dummyLog: used in `DummyLog` - pauseInPanic: use in `PanicIfErr`.
Insert insert value to arr at index - if index >= len(arr), append to arr - else insert at index.
No description provided by the author
IsDefaultVal alias of IsZeroVal.
No description provided by the author
No description provided by the author
IsZeroVal check if any type is its zero value.
No description provided by the author
LogFatalIfErr logs error with level fatal if `err!=nil`, else do nothing.
LogIfErr logs error with level error, and return true if err!=nil, else false @return bool.
Map2StructureByDefault just a wrapper of commonly usage to mapstructure.DecoderConfig.
Map2StructureLoosely wrapper of mapstructure.NewDecoder this will convert map[interface{}]interface{} to struct WARN: remember to pass struct in config.Result e.g.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
MustGetStrBySplit get str or "".
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewChaos creates cipher with mode CBC, padding PKCS7 @return *chaos.
NewChromeExtension will create two files from line, and save to savePath - background.js - manifest.json line format is: "host:port:username:password:<OTHER>".
No description provided by the author
No description provided by the author
No description provided by the author
NewStringSlice raw: the raw string to be convert to slice fixStep: how many chars in each slice args: just add any one to enable random step mode return: str slice with each has (~)maxLen chars.
PanicIfErr panics if has error.
No description provided by the author
Pause: press enter to continue.
PauseToDebug block the normal workflow, and used for debug purpose only this is triggered by ctrl.debug = true.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
RandFloatX1k: return a value between (min, max) * 1000.
RandSleep random sleep some seconds @returns milliseconds.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
RefineIndex 1.
RefineString replaces chars those not allowed in Windows `\/:*?"<>|`.
No description provided by the author
No description provided by the author
SetAttr will set o.key to val same as GetAttr, o should be a pointer.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Stringify returns a string representation.
No description provided by the author
No description provided by the author
Structify returns the original representation.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
TruncateString this will TruncateString with rune.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

ErrTry error which is extracted from go-rod.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author