Documentation ¶
Index ¶
- Constants
- Variables
- func AfterStopFunc(d time.Duration, f func(<-chan struct{}))
- func AfterStopWithContext(d time.Duration, f func(context.Context))
- func FileCopy(source, dest string) (err error)
- func FileExist(file string) bool
- func FileFindPath(fname string) (string, error)
- func FileIsBinary(content string) bool
- func FileIsDir(path string) bool
- func FileMove(src, dest string) error
- func FileSize(path string) int64
- func FormatBinary(value int64) string
- func FormatBinaryDecimal(value int64) string
- func FormatByStr(tpl string, t int64) string
- func FormatBytesString(b int64) string
- func FormatBytesStringOhMyGod(b int64) string
- func GetMonthRange(year, month int) (beginTime, endTime int64, err error)
- func GetWeek(t time.Time) int
- func IsWindows() bool
- func MacAddr() (upMac []string, err error)
- func NumberID() string
- func ParseBinaryString(value string) (i int64, err error)
- func ParseBytes(value string) (int64, error)
- func ParseStringDecimal(value string) (i int64, err error)
- func RandAlphaString(length int) string
- func RandBytes(length int) []byte
- func RandInt(min, max int) int
- func RandInt32(min, max int32) int32
- func RandInt64(min, max int64) int64
- func RandInts(from, to, size int) []int
- func RandLower(l int) string
- func RandString(n int) string
- func RandUpper(l int) string
- func Retry(n uint, interval time.Duration, fn func() error) (err error)
- func Round(x float64, place int32) float64
- func SlowFunc(threshold time.Duration, sf func() error, cb func()) error
- func TimeToStr(t time.Time, format ...string) string
- func TimestampToStr(t int64, format ...string) string
- func UUID() string
- func WithContext(ctx context.Context, n uint, interval time.Duration, fn func() error) (err error)
- func WithContextFunc(ctx context.Context, f func()) context.Context
- func XID() string
- type CmdOutput
- type IDGenerator
- type Options
Constants ¶
const ( KiB // 1 KiB = 1024 Bytes MiB // 1 MiB = 1048576 Bytes GiB // 1 GiB = 1073741824 Bytes TiB // 1 TiB = 1099511627776 Bytes PiB // 1 PiB = 1125899906842624 Bytes EiB // 1 EiB = 1152921504606846976 Bytes )
binary units (IEC 60027)
const ( KB = 1000 MB = 1_000_000 GB = 1_000_000_000 TB = 1_000_000_000_000 PB = 1_000_000_000_000_000 EB = 1_000_000_000_000_000_000 )
const EnvVarHome = "HOME"
const EnvVarTMP = "TMP"
Variables ¶
var ErrorForceKill = errors.New("force killed failed")
var ID id
Functions ¶
func AfterStopFunc ¶
AfterStopFunc 超时停止协程,关闭协程。使用原始channel实现 这里新建了两个channel是防止关闭一个已经关闭的channel导致panic,这里还有优化点。 该函数主使用场景,比如防止扫描磁盘时间过长,在规定时间里获取结果.
func AfterStopWithContext ¶
AfterStopWithContext 超时停止协程,关闭协程。使用context实现.
func FileFindPath ¶
FileFindPath 获取文件名路径,首先判断文件是否可以直接访问,优先获取当前可执行文件夹下,再去找工作路径下.
func FormatBinary ¶
FormatBinary formats bytes integer to human readable string according to IEC 60027. For example, 31323 bytes will return 30.59KB.
func FormatBinaryDecimal ¶
FormatBinaryDecimal formats bytes integer to human readable string according to SI international system of units. For example, 31323 bytes will return 31.32KB.
func FormatByStr ¶
FormatByStr 将字符串中的时间变量(y年/m月/d日/h时/i分/s秒)转换成时间字符串.
func FormatBytesString ¶
FormatBytesString 格式化bytes单位成可阅读单位形式,由于电脑制造商使用的是1000为单位计算磁盘大小 所以基本上使用该函数格式化存储大小.
func FormatBytesStringOhMyGod ¶
FormatBytesStringOhMyGod 格式化存储大小,理论上应该使用该方式格式化存储大小,但是实际上不是这样的,呜呜呜呜呜呜.
func GetMonthRange ¶
GetMonthRange 获得指定年份和月份的起始unix时间和截止unix时间.
func ParseBinaryString ¶
ParseBinaryString parses human readable bytes string to bytes integer. For example, 6GiB (6Gi is also valid) will return 6442450944.
func ParseBytes ¶
ParseBytes parses human readable bytes string to bytes integer. For example, 6GiB (6Gi is also valid) will return 6442450944, and 6GB (6G is also valid) will return 6000000000.
func ParseStringDecimal ¶
ParseStringDecimal parses human readable bytes string to bytes integer. For example, 6GB (6G is also valid) will return 6000000000.
func Retry ¶
Retry calls the `fn` and if it returns the error, retry to call `fn` after `interval` duration. The `fn` is called up to `n` times.
func TimestampToStr ¶
TimestampToStr Timestamp将unix时间转为时间字符串.
func WithContext ¶
WithContext stops retrying when the context is done.
func WithContextFunc ¶
WithContextFunc returns a copy of parent context that is cancelled when an os interrupt signal is received. The callback function f is invoked before cancellation.