gobase

package module
v1.2.24041 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: BSD-3-Clause Imports: 27 Imported by: 4

Documentation

Index

Constants

View Source
const (
	U8_1    byte   = 1
	U8_0    byte   = 0
	U8_MAX  byte   = ^U8_0
	U32_1   uint32 = 1
	U32_0   uint32 = 0
	U64_0   uint64 = 0
	I64_1   int64  = 1
	U64_1   uint64 = 1
	U64_MAX uint64 = ^U64_0
)
View Source
const (
	EMPTY_STRING string = ""
	QUOTECHR            = '"'
)
View Source
const (
	DURA_DAY time.Duration = time.Hour * 24
)

Variables

View Source
var (
	GoFunCatchException bool = true
	OnCatchAllPanic     func(err interface{}, args ...interface{})
)
View Source
var (
	PathSeparator = "\\"
	RootPath      = ""
)
View Source
var (
	SIZE_KB uint64 = 1024
	SIZE_MB        = 1024 * SIZE_KB
	SIZE_GB        = 1024 * SIZE_MB
	SIZE_TB        = 1024 * SIZE_GB
)
View Source
var (
	ZeroTime      time.Time // UTC
	ZeroTimeLocal           = ZeroTime.Local()

	START_Time     time.Time     = StrToTimeDef("00", "04", time.UTC, ZeroTime)
	START_Duration time.Duration = ParseDuration("0s")

	UnixZeroTime time.Time = time.Unix(0, 0).Local() // 默认是Local
)
View Source
var (
	SPACE_BYTES []byte = []byte(" ")
)

Functions

func AbsDuration

func AbsDuration(t1 time.Duration) time.Duration

func AbsInt

func AbsInt(x int) int

func AddPrefixForWidth

func AddPrefixForWidth(src string, width int, prefix string) string

func AddSuffixForWidth

func AddSuffixForWidth(src string, width int, suffix string) string

func AppendAllFile

func AppendAllFile(srcFile string, dataFile string) error

*

  • srcFile : 存的文件 dataFile 数据文件 将dataFile 加入到srcFile中去

func AppendFile

func AppendFile(fileName string, fileData []byte) (int, error)

func AppendFileEx

func AppendFileEx(fileName string, fileData []byte, forceDir bool) (int, error)

func BetweenTime

func BetweenTime(t1, t2 time.Time) time.Duration

func Binary2Hex

func Binary2Hex(bt []byte) string

2进制转到16进制

func BitTrimPrefix

func BitTrimPrefix(v uint64, bitN byte) uint64

* 保留后面的N 位

BitTrimPrefix(binary: 100110, 3)=binary: 110;

func Bool2Byte

func Bool2Byte(v bool) byte

func Bool2Str

func Bool2Str(v bool) string

func BufStart

func BufStart(buf []byte, start, l int) []byte

func BufToHexStr

func BufToHexStr(buf []byte, l int, spliterstr string) string

func BytesAppendUInt64_LE

func BytesAppendUInt64_LE(buf []byte, v uint64) []byte

func BytesCheckGrow

func BytesCheckGrow(buf []byte, n int) []byte

Grow grows b's capacity, if necessary, to guarantee space for another n bytes. After Grow(n), at least n bytes can be written to b without another allocation. If n is negative, Grow panics.

func BytesCheckSize

func BytesCheckSize(buf []byte, start, l int) []byte

func CRC24Q

func CRC24Q(buf []byte, len int) uint32

func CRC24QBuf

func CRC24QBuf(buf []byte) uint32

func Cfmod

func Cfmod(x, y float64) float64

func CheckAddPrefix

func CheckAddPrefix(s, prefix string) (added bool, rval string)

func CheckAddQuoteChr

func CheckAddQuoteChr(s string, prefix, suffix rune) string

func CheckAddSuffix

func CheckAddSuffix(s, suffix string) (added bool, rval string)

func CheckAllStrsIsNotEmpty

func CheckAllStrsIsNotEmpty(strs ...string) bool

func CheckByteIn

func CheckByteIn(v byte, sets ...byte) bool

func CheckGetStrlist

func CheckGetStrlist(strs []string, idx int, def string) string

func CheckGetValInlst

func CheckGetValInlst(lst []interface{}, idx int, def interface{}) interface{}

func CheckRotateFile

func CheckRotateFile(filename string) error

1. 如果文件已经存在, 则对之前的文件进行更名

func CheckRotateFileAfterCreateFile

func CheckRotateFileAfterCreateFile(filename string) (fn *os.File, err error)
  1. 如果文件已经存在, 则对之前的文件进行更名, 更名失败 返回异常
  2. 更名成功则创建新文件的os.file. 创建成功则返回, 失败,进行重试, 超过10次返回异常 创建的文件成功会被清空

func CheckTrimPrefix

func CheckTrimPrefix(s, prefix string) (bool, string)

func CheckTrimQuoteChr

func CheckTrimQuoteChr(s string, prefix, suffix byte) (bool, string)

*

截掉前后字符

func CheckTrimQuoteString

func CheckTrimQuoteString(s string, prefix, suffix string) (bool, string)

*

截掉前后字符串

func CheckTrimSuffix

func CheckTrimSuffix(s, suffix string) (bool, string)

func CloneBytes

func CloneBytes(src []byte, offset int, l int) []byte

func CloneBytesEx

func CloneBytesEx(src []byte, offset int, l int) []byte

func CmpAndSetBitValue

func CmpAndSetBitValue(ival uint64, bitN byte, cmpbitVal, newbitVal byte) (changed bool, newval uint64)

**

bitN 从0开始
cmpbitVal, newbitVal, 只能是0或者1
比较低bitN是否为cmpbitval, 如果是则进行设置为newbitval
changed :true, 表示有修改

func CombineFilePath

func CombineFilePath(parts ...string) string

func CombineIfFirstNotEmpty

func CombineIfFirstNotEmpty(s1, s2 string) string

func CombineIfNotEmpty

func CombineIfNotEmpty(s1, s2 string) string

func CompareIgnoreCase

func CompareIgnoreCase(s1, s2 string) int

*

The result will be 0 if a==b, -1 if a < b, and +1 if a > b.

func ContainElement

func ContainElement(s string, ele string, sep rune) (rval bool)

*

false = ContainElement("1,2,3,16", ",", "6")

func CopyFile

func CopyFile(src, dst string) (w int64, err error)

func CreateIfExistsThenRename

func CreateIfExistsThenRename(name string) (*os.File, string, error)

func CreateRewrite

func CreateRewrite(fileName string) (*os.File, error)

func CutIfMore

func CutIfMore(s string, n int, moreflagstr string) string

*

CutIfMore(txt, 10, "..."))

func CutLeft

func CutLeft(s string, n int) (cut string, remain string)

func CutNPrefixFunc

func CutNPrefixFunc(s string, idx int, cutflag byte, CheckCutBreakFunc func(c rune) bool) (cut string, remain string)

func CutNSuffixFunc

func CutNSuffixFunc(s string, idx int, cutflag byte, CheckCutBreakFunc func(c rune) bool) (cut string, remain string)

func CutPrefixByRune

func CutPrefixByRune(s string, idx int, cutflag byte, c rune) (cut string, remain string)

**

idx 从0开始
"/", "中国/人民", CutPrefixByRune("/中国/人民", 0, 1, "/")
"/中国/", "人民", CutPrefixByRune("/中国/人民", 1, 1, "/")

func CutPrefixFunc

func CutPrefixFunc(s string, cutflag byte, CheckCutBreakFunc func(c rune) bool) (cut string, remain string)

*

    如果CheckCutBreakFunc 一直为false, cut则返回"", remain则返回源字符串
    返回true表示从该字符进行截断

    cutflag 0: "中国/人","民"
    cutflag 1: "中国/人民",""
    str := "中国/人民";
	plug, remain := CutPrefixFunc(str, 0, func(c rune) bool {
		if c == '民'{
			return true;
		}
		return false;
	})

    cutflag 0: "中国","/人民"
    cutflag 1: "中国","/人民"
    str := "中国/人民";
	plug, remain := CutPrefixFunc(str, 0, func(c rune) bool {
		if c == '/'{
			return true;
		}
		return false;
	})

	fmt.Println(CutPrefixFunc("../abc.txt", 1, func(c rune) bool {
		if c == '.' || c=='/'{
			return false;
		}
		return true;
	}))
   ../, abc.txt

func CutSuffixByRune

func CutSuffixByRune(s string, idx int, cutflag byte, c rune) (cut string, remain string)

**

idx 从0开始
"/人民", "/中国", CutSuffixByRune("/中国/人民", 0, 1, "/")
"/中国/人民", "", CutSuffixByRune("/中国/人民", 1, 1, "/")

func CutSuffixFunc

func CutSuffixFunc(s string, cutflag byte, CheckCutBreakFunc func(c rune) bool) (cut string, remain string)

**

如果CheckCutBreakFunc 一直为false, cut则返回"", remain则返回源字符串

func DateString

func DateString(val time.Time) string

func DateTimeIDString

func DateTimeIDString(val time.Time) string

func DateTimeString

func DateTimeString(val time.Time) string

func DateTimeString2

func DateTimeString2(val time.Time) string

**

  • 如果时间为空,则返回""

func DateTimeString3

func DateTimeString3(val time.Time) string

func DateTimeStringForShortShow

func DateTimeStringForShortShow(val time.Time) string

func DateTimeStringForShow

func DateTimeStringForShow(val time.Time) string

func DateYYMM

func DateYYMM(val time.Time) string

func DateYYYYMM

func DateYYYYMM(val time.Time) string

func DateYYYYMMDD

func DateYYYYMMDD(val time.Time) string

func DayOfYear

func DayOfYear(atime time.Time) string

func DecimalToAny

func DecimalToAny(num, n, count int) string

inttohex DecimalToAny(113, 16, 2) = 71

func DecodeCRCBuf

func DecodeCRCBuf(src []byte) []byte

func DeferCatchPanic

func DeferCatchPanic(args ...interface{})

func DelNonAsciiChar

func DelNonAsciiChar(s []byte) string

func DelNonAsciiCharEx

func DelNonAsciiCharEx(s []byte, splitchar byte) string

func DelNonChineseChar

func DelNonChineseChar(s string) string

*

包含中文和英文

func DelNonChineseCharEx

func DelNonChineseCharEx(s string, splitchar rune) string

func DelNonPrintChar

func DelNonPrintChar(s string) string

func DeleteBuf

func DeleteBuf(buf []byte, startidx, n int) (newBuf []byte)

func DeleteFileNameExt

func DeleteFileNameExt(fileName string) string

func DeleteFileOrDir

func DeleteFileOrDir(strPath string) error

*

移除 文件或者文件夹

func DeleteStrlstEle

func DeleteStrlstEle(strs []string, fn func(s string) bool) []string

**

删除符合条件的元素

func DetectBOMType

func DetectBOMType(data []byte) int

*

0:无BOM
1:UTF8

func DurationStr

func DurationStr(d time.Duration) string

StatusString returns a string representing the duration in the form "72h3m0.5s". Leading zero units are omitted. As a special case, durations less than one second format use a smaller unit (milli-, micro-, or nanoseconds) to ensure that the leading digit is non-zero. The zero duration formats as 0s. 去掉了秒的小数

func EnablePanicRecordFile

func EnablePanicRecordFile(logpath string)

func EncodeCRCBuf

func EncodeCRCBuf(src []byte) []byte

func EndOfADay

func EndOfADay(day time.Time) time.Time

func EscapeJsonStr

func EscapeJsonStr(str string) string

Copy From DxValue.Record

func EscapeJsonStrSimple

func EscapeJsonStrSimple(str string) string

func EscapeSQLStr

func EscapeSQLStr(str string) string

func EscapeStr4Line

func EscapeStr4Line(str string) string

func ExecCmdLine

func ExecCmdLine(cmdLine string, arg_spliter string) error

func ExecCmdNoWait

func ExecCmdNoWait(cmdLine string) (*exec.Cmd, error)

func ExecCmdNoWaitNoSettingIO

func ExecCmdNoWaitNoSettingIO(cmdLine string) (*exec.Cmd, error)

func ExecShell

func ExecShell(cmdLine string) error

**

  • exeshell("del *.log")

func ExecShellAndNoWait

func ExecShellAndNoWait(cmdLine string) error

func ExecShellOutput

func ExecShellOutput(cmd string) (err error, str string)

func ExecShellWithIO

func ExecShellWithIO(cmdLine string, rd io.Reader, outstd, outerr io.Writer) error

* sb := NewBytesBuilder() ExecShellWithIO("dir c:\\*.*", nil, sb, sb) sb.StatusString();

func ExecShellWithStdIO

func ExecShellWithStdIO(cmdLine string) error

**

  • exeshell("del *.log")

func ExecWithStdIO

func ExecWithStdIO(cmdLine string) error

**

  • exec("perl xxx *.log")

func ExtractFileName

func ExtractFileName(fileName string) string

*

"W:\\temp\\测试删除文件夹\\a.txt"  -> a.txt

func ExtractFileNameWithOutPathAndExt

func ExtractFileNameWithOutPathAndExt(fileName string) string

func ExtractFilePath

func ExtractFilePath(fileName string) string

func FastByte2String

func FastByte2String(bt []byte) string

func FileIs

func FileIs(fileName string) int

**

0: 不存在
1: 文件
2: 目录

func FileIsExists

func FileIsExists(fileName string) bool

exists returns whether the given file or directory exists or not

func FileMTime

func FileMTime(fp string) (time.Time, error)

get file modified time

func FileNameAddfix

func FileNameAddfix(fileName, prefix, suffix string) string

func FileSize

func FileSize(fp string) (int64, error)

get file size as how many bytes

func FindNonElement

func FindNonElement(s1, s2 string, sep rune) string

*

查找s2中不存在与s1中的元素
FindNonElement("1,2,3", "3,4,2,5") = "4,5"

func FixintervalLastTime

func FixintervalLastTime(t time.Time, fixinterval time.Duration) time.Time

*

FixIntervalLastTime("2020-06-05 13:13:29", time.Minute * 15) = 2020-06-05 13:00:00

func FixintervalNextTime

func FixintervalNextTime(t time.Time, fixinterval time.Duration) time.Time

*

FixIntervalNextTime("2020-06-05 13:13:29", time.Minute * 15) = 2020-06-05 13:15:00

func FixintervalOffsetTime

func FixintervalOffsetTime(t time.Time, fixinterval time.Duration, offsetN int) time.Time

*

FixintervalOffsetTime("2020-06-05 13:13:29", time.Minute * 15, 0) = 2020-06-05 13:00:00

func Float32ToStr

func Float32ToStr(val float64) string

func Float64ToStr

func Float64ToStr(val float64) string

**

1 = "1"
0.1 = "0.1"

func ForceAllPath

func ForceAllPath(strPath string) error

func ForceCreateFilePath

func ForceCreateFilePath(fileName string) error

func ForceCreatePath

func ForceCreatePath(strPath string) bool

func FormatFloatVlst

func FormatFloatVlst(fmtstr string, singalw int, totalwidth int, args ...float64) string

FormatFloatVlst

func GetAbsPath

func GetAbsPath(basePath, relaPath string) (string, error)

*

获取绝对路径

func GetAreaBK

func GetAreaBK(s string, start, end string, idx int) string

* 不支持....

func GetBetween

func GetBetween(str string, start, end string, idx int) string

`<td>a</td><td>b</td>` GetBetween(str, "<td>", "</td>") = a

GetBetween("$now$", "$", "$") = "now"

func GetBetweenEx

func GetBetweenEx(str string, start, end string, idx int) (ok bool, val string)

`<td>a</td><td>b</td>` GetBetween(str, "<td>", "</td>") = a

GetBetween("$now$", "$", "$") = "now"

func GetBitG

func GetBitG(buf []byte, startBitN int, l int) float64

注 1:符号数值表示记录数据的符号和数值。最高有效位 MSB 为 0 表示正数,为 1 表示负数,其余位是数据的数值。

func GetBitI16

func GetBitI16(buf []byte, startBitN int, l int) int16

func GetBitI32

func GetBitI32(buf []byte, startBitN int, l int) int32

第一位作为符号位

func GetBitI64

func GetBitI64(buf []byte, startBitN int, l int) int64

第一位作为符号位

func GetBitI8

func GetBitI8(buf []byte, startBitN int, l int) int8

func GetBitOnU32

func GetBitOnU32(v uint32) (n byte)

========================================= **

位为1的数量

func GetBitOnU64

func GetBitOnU64(v uint64) (n byte)

func GetBitU

func GetBitU(buf []byte, startBitN int, l int) uint32

func GetBitU16

func GetBitU16(buf []byte, startBitN int, l int) uint16

func GetBitU64

func GetBitU64(buf []byte, startBitN int, l int) uint64

func GetBitU8

func GetBitU8(buf []byte, startBitN int, l int) byte

func GetBitV_U32

func GetBitV_U32(v uint32, bitN byte) byte

* 从0开始

func GetBitV_U64

func GetBitV_U64(v uint64, bitN byte) byte

func GetBitValue

func GetBitValue(ival uint64, bitN byte) byte

1:位第一位

func GetBitValue0

func GetBitValue0(ival uint64, bitN byte) byte

0:位第一位

func GetBoolValue

func GetBoolValue(val interface{}, def bool) bool

func GetCurrentDirectory

func GetCurrentDirectory() (path string, err error)

func GetCurrentGoRoutineID

func GetCurrentGoRoutineID() uint64

func GetCurrentWorkingPath

func GetCurrentWorkingPath() (path string)

**

带path分隔符

func GetDateTimeValue

func GetDateTimeValue(val interface{}, def time.Time) time.Time

func GetDayOfWeek

func GetDayOfWeek(val time.Time) byte

func GetDecimalBitN

func GetDecimalBitN(v int64, n int64) int

*

  • 取10进制的 各个位上的值
  • n <=1 为个位, 2:十位 ....
  • GetDecimalBitN(12304, 1) = 4, % 取余数

func GetDecimalBitNEx

func GetDecimalBitNEx(v int64, n int64) int

*

  • 取10进制的 各个位上的值
  • n 1,10,1000, 10000 ..
  • GetDecimalBitNEx(12304, 1) = 4,

func GetExecShellCmd

func GetExecShellCmd(cmdLine string) *exec.Cmd

func GetExecuteFileDirectory

func GetExecuteFileDirectory() (path string)

*

  • 最后不带路径符

func GetExecuteFileName

func GetExecuteFileName() (name string)

*

返回执行文件名

func GetFirstFromVars

func GetFirstFromVars(arg interface{}) interface{}

*

如果arg 是切片[]interface 则获取第一个元素

func GetFloat64Value

func GetFloat64Value(val interface{}, def float64) float64

func GetIdxFloat64ValFromVars

func GetIdxFloat64ValFromVars(arg interface{}, idx int, def float64) float64

func GetIdxIntValFromVars

func GetIdxIntValFromVars(arg interface{}, idx int, def int) int

func GetIdxStrValFromVarsDef

func GetIdxStrValFromVarsDef(arg interface{}, idx int, def string) string

func GetIdxValFromVars

func GetIdxValFromVars(arg interface{}, idx int) interface{}

*

如果arg 是切片[]interface 则获取第idx元素
idx 从0开始

func GetIdxValFromVarsDef

func GetIdxValFromVarsDef(arg interface{}, idx int, def interface{}) interface{}

func GetInt32Value

func GetInt32Value(val interface{}, def int32) int32

func GetInt64Value

func GetInt64Value(val interface{}, def int64) int64

func GetLastNumStr

func GetLastNumStr(str string, maxl int) string

func GetMonthDayN

func GetMonthDayN(year, month int) int

func GetNewFileUseIncSN

func GetNewFileUseIncSN(fileName string) string

*

XXXX.dat -> XXX.1.dat(XXX.2.dat)

func GetRelativePath

func GetRelativePath(basePath, path2 string) (string, error)

**

求两个绝对路径的相对路径
  写一个函数计算出两个绝对路径(如path1 = /a/b/c/d, path2 = /a/e/f)的相对路径为 ../../e/f

func GetStrValue

func GetStrValue(val interface{}, def string) string

func GetU64BitsU

func GetU64BitsU(v uint64, startBit, endBit int) uint64

**

获取v 的位数 的值
binary: 0010 1101
GetU64BitsU(v, 2, 3) = binary: 11

从startBit到endBit 包含endBit

startBit 从0开始计数

func GetU64BitsU_L

func GetU64BitsU_L(v uint64, startBit, l int) uint64

**

从startBit开始数 l位的值

func GetU8BitValue0

func GetU8BitValue0(ival byte, bitN byte) byte

func HEX2BCD

func HEX2BCD(val int) (int, error)

/ <summary> / HEX转成10进制 / HEX中不能有字母 / 0x65036 -> 65036 / </summary>

func HEX2BCDDef

func HEX2BCDDef(val, def int) int

func HashStr

func HashStr(str string) int64

func HaveAnyGBK

func HaveAnyGBK(data []byte) bool

*

GB2312标准共收录6763个汉字,其中一级汉字3755个,二级汉字3008个;
GBK共收入21886个汉字和图形符号。
GBK: 8140至FEFE

func HexStrToBuf

func HexStrToBuf(hexstr string) []byte

func HexToDateTime

func HexToDateTime(hex string, def time.Time) time.Time

func HexToInt

func HexToInt(hex string) int

func HexValue

func HexValue(chr rune) int

func HumanDuration

func HumanDuration(dura time.Duration) string

func HumanFilesize

func HumanFilesize(sizebytes int64) string

func HumanFilesizeU

func HumanFilesizeU(sizebytes uint64) string

func HumanSizeStrToSize

func HumanSizeStrToSize(str string) int64

**

HumanSizeToSize("1024KB")

func HumanTimeStr

func HumanTimeStr(secs int64) string

func HumanTimeStrFromMinutes

func HumanTimeStrFromMinutes(minutes int64, spliter string) string

func HumanTimeStrFromMinutesInt

func HumanTimeStrFromMinutesInt(minutes int, spliter string) string

func IncDay

func IncDay(atime time.Time, num int) time.Time

func IncMonth

func IncMonth(atime time.Time, num int) time.Time

func IncYear

func IncYear(atime time.Time, num int) time.Time

func InsertBeforeLineFile

func InsertBeforeLineFile(fileName string, idx_before_line int64, fileData []byte) error

func InsertBuf

func InsertBuf(buf []byte, startidx int, val []byte) (newBuf []byte)

func Int64_BEBytes

func Int64_BEBytes(val int64) []byte

func Int64_FromBEBytes

func Int64_FromBEBytes(val []byte) int64

func Int8ListToStrs

func Int8ListToStrs(lst []int8, sep string) string

func IntFromU

func IntFromU(v uint64, bitN byte) int64

**

和 = rtklib exsign
1: 保留bitN位
2: 最高位为1还是0   1:为负数, 0:为正数

func IsAsciiPrintByte

func IsAsciiPrintByte(c byte) bool

ASCII可显示字符

func IsAsciiPrintChar

func IsAsciiPrintChar(chr rune) bool

func IsAsciiPrintStr

func IsAsciiPrintStr(src string) bool

func IsChineseChar

func IsChineseChar(c rune) bool

* 字符集 字数 Unicode 编码 基本汉字 20902字 4E00-9FA5 // 一 ~ 龥 (简繁) 基本汉字补充 90字 9FA6-9FFF 扩展A 6592字 3400-4DBF 扩展B 42720字 20000-2A6DF 扩展C 4153字 2A700-2B738 扩展D 222字 2B740-2B81D 扩展E 5762字 2B820-2CEA1 扩展F 7473字 2CEB0-2EBE0 扩展G 4939字 30000-3134A 康熙部首 214字 2F00-2FD5 部首扩展 115字 2E80-2EF3 兼容汉字 477字 F900-FAD9 兼容扩展 542字 2F800-2FA1D PUA(GBK)部件 81字 E815-E86F 部件扩展 452字 E400-E5E8 PUA增补 207字 E600-E6CF 汉字笔画 36字 31C0-31E3 汉字结构 12字 2FF0-2FFB 汉语注音 43字 3105-312F 注音扩展 22字 31A0-31BA 〇 1字 3007

func IsHexChar

func IsHexChar(chr rune) bool

func IsHexStr

func IsHexStr(src string) bool

* src 长度必须是2的倍数, 必须都是HEX字符, 不能包含空格

func IsInMultiSection

func IsInMultiSection(exp, s string) string

**

00:00-07:00,08:00-10:00,11:00-12:00

func IsInSection

func IsInSection(exp, s string) bool

**

00:00-07:00

func IsLeapYear

func IsLeapYear(year int) bool

func IsLinux

func IsLinux() bool

func IsPrintStr

func IsPrintStr(src string) bool

func IsSameDay

func IsSameDay(time1, time2 time.Time) bool

func IsSameMonth

func IsSameMonth(time1, time2 time.Time) bool

func IsWindows

func IsWindows() bool

func JoinDateAndTime

func JoinDateAndTime(dateT, timeT time.Time) time.Time

func JoinDateAndTimeStr

func JoinDateAndTimeStr(dateT time.Time, timestr string) time.Time

func JoinDateAndTimeStrFormat

func JoinDateAndTimeStrFormat(dateT time.Time, timestr, timestr_format string) time.Time

func JoinIfNoEmpty

func JoinIfNoEmpty(chk string, sep string, args ...string) string

func LastChrCnt

func LastChrCnt(s string, c byte) int

func LeftStr

func LeftStr(s string, n int) string

func LocationCopy

func LocationCopy(t1, loctime time.Time) time.Time

**

loctime 不能为 ZeroTime

func MD5

func MD5(str string) string

func MD5Buf

func MD5Buf(data []byte) string

func MD5SumFile

func MD5SumFile(filePath string) string

func MSecOfDuration

func MSecOfDuration(time time.Duration) int64

func MakeVars

func MakeVars(arg ...interface{}) interface{}

func MapEncode

func MapEncode(strMap map[string]string, kvsep, itmsep string, escapeflag bool, bb io.Writer)

func MaxTime

func MaxTime(t0 time.Time, t1 time.Time) time.Time

func MillisecondOf

func MillisecondOf(start, end time.Time) int64

func MinInt

func MinInt(a, b int) int

func MinTime

func MinTime(t0 time.Time, t1 time.Time) time.Time

func MinuteOfDuration

func MinuteOfDuration(time time.Duration) int64

func NewFileData

func NewFileData(fileName string, fileData []byte) (int, error)

func NewFileFromReader

func NewFileFromReader(fileName string, reader io.Reader) (int, error)

func NewFileNameIfExistsThenIncSN

func NewFileNameIfExistsThenIncSN(fileName string) string

func NextMonthV

func NextMonthV(month int) int

func NextMonthYM

func NextMonthYM(y, m int) (y1, m1 int)

func NowIDString

func NowIDString() string

func NowString

func NowString() string

func NowStringEx

func NowStringEx() string

func ObjectHexAddr

func ObjectHexAddr(v interface{}) string

func PanicRecordFile

func PanicRecordFile(err interface{}, args ...interface{})

func ParseDuraStr

func ParseDuraStr(s string) time.Duration

func ParseDuration

func ParseDuration(timeExp string) time.Duration

func ParseTimeFmt

func ParseTimeFmt(strPattern string, _t time.Time) string

func ParserJsonEscapeStr

func ParserJsonEscapeStr(escapedstr string) string

解码转义字符,将"\u6821\u56ed\u7f51\t02%20得闲"这类字符串,解码成正常显示的字符串

func PathBase

func PathBase(path string) string

func PathEscape

func PathEscape(s string) string

PathEscape escapes the string so it can be safely placed inside a URL path segment, replacing special characters (including /) with %XX sequences as needed.

func PathExists

func PathExists(path string) (bool, error)

** 如果返回的错误为nil,说明文件或文件夹存在 如果返回的错误类型使用os.IsNotExist()判断为true,说明文件或文件夹不存在 如果返回的错误为其它类型,则不确定是否在存在

func PathUnescape

func PathUnescape(s string) (string, error)

PathUnescape does the inverse transformation of PathEscape, converting each 3-byte encoded substring of the form "%AB" into the hex-decoded byte 0xAB. It returns an error if any % is not followed by two hexadecimal digits.

PathUnescape is identical to QueryUnescape except that it does not unescape '+' to ' ' (space).

func QueryEscape

func QueryEscape(s string) string

QueryEscape escapes the string so it can be safely placed inside a URL query.

func QueryUnescape

func QueryUnescape(s string) (string, error)

QueryUnescape does the inverse transformation of QueryEscape, converting each 3-byte encoded substring of the form "%AB" into the hex-decoded byte 0xAB. It returns an error if any % is not followed by two hexadecimal digits.

func RandBuf

func RandBuf(len int) []byte

*

比较耗cpu

func RandFloat64

func RandFloat64(f float64) float64

func RandHexString

func RandHexString(len int) string

60个纤程同时进行测试没有异常

func RandKeyString

func RandKeyString(len int) string

60个纤程同时进行测试没有异常

func RandNumString

func RandNumString(len int) string

func RandNumStringWithout4

func RandNumStringWithout4(len int) string

func RandPass0String

func RandPass0String(len int) string

func RangeByteFromHexStr

func RangeByteFromHexStr(hexstr string, cb func(v byte) bool) int

func RangeFiles

func RangeFiles(path string, maxlevel int, fn func(path string, file os.FileInfo) bool, onerr func(dirname string, err error) bool) error

**

Range path下的文件和目录
maxlevel 表示目录层级
  0: 表示搜索所有
  1:表示获取当前目录(不会进入下一级目录)
fn: 如果返回 false 表示退出当前目录搜索, path为当前文件所在路径
onerr 返回false 则返回退出当前目录的range

func RangeStringSep

func RangeStringSep(s string, sep rune, cb func(idx int, s1 string) bool) int

**

RangeStringSep("a01;a02", ';', fn);  // 2次
RangeStringSep("a01", ';', fn);      // 1次
RangeStringSep("a01;", ';', fn);      // 1次
RangeStringSep("a01;;", ';', fn);    // 2次

func RangeStringSep2

func RangeStringSep2(s string, cb func(idx int, s1 string) bool, sep0, sep1 rune) int

**

RangeStringSep2("a01;a02", fn, ';', ',');

func RangeStringSplit

func RangeStringSplit(s string, sep string, cb func(idx int, s string) bool) int

* RangeStringSplit("a\r\n汉字b\r\n", "\r\n", func)

func ReadDir

func ReadDir(dirname string) ([]os.FileInfo, error)

ReadDir reads the directory named by dirname and returns a list of directory without sort.

func ReadFile

func ReadFile(fileName string) ([]byte, error)

func ReadFileBlockBuf

func ReadFileBlockBuf(fileName string, cb func(block []byte) bool, makebuffunc func() []byte) (int64, error)

**

func ReadFileBlockBufOffset

func ReadFileBlockBufOffset(fileName string, offset int64, cb func(block []byte) bool, makebuffunc func() []byte) (int64, error)

**

func ReadFileLine

func ReadFileLine(fileName string, cb func(idx int64, line []byte) bool) (int64, error)

**

  • 依次读取行, 执行cb函数
  • cb函数如果返回false则中断读取, idx从0开始
  • 返回读取行数和错误

func ReadLBytes

func ReadLBytes(r io.Reader, buf []byte, l int) error

读取指定长度的数据, 直到返回错误或者读取完成 l:=0 表示读取buf的长度

func ReadPerLine

func ReadPerLine(reader io.Reader, cb func(idx int64, line []byte) bool) (int64, error)

func ReadPerLineEx

func ReadPerLineEx(reader io.Reader, cb func(idx int64, line []byte) bool) (int64, error)

func ReadPerLineFile

func ReadPerLineFile(filename string, offset int64, cb func(idx int64, line []byte) bool) (int64, error)

func RenameFile

func RenameFile(afile string, newFileName string) error

func ReplaceAll

func ReplaceAll(s string, old, new string) string

* 忽略大小写

func ReplaceArea

func ReplaceArea(s string, start, end string, new string) string

* 忽略大小写

`<td>a</td><td>b</td>`
ReplaceArea(str, "<td>", "</td>", "<td>abc</td>") = <td>abc</td><td>abc</td>

func ReplaceMultiAny2One

func ReplaceMultiAny2One(s string, any, new string) string

*

ReplaceMultiAny2One("a    b    c     d    ", " ", ":");   -> "a:b:c:d:"
ReplaceMultiAny2One("a    b    c     d    "," "," ")->"a b c d "
ReplaceMultiAny2One("ababaaa aab ac d aaa ","ab","x")->"xaaa ax ac d aaa "
ReplaceMultiAny2One("aaaaa aab ac d aaa ", "aa", "x")->"xa xb ac d xa"

func ReplaceMultiSpace2One

func ReplaceMultiSpace2One(s string, new string) string

*

s := "a    b    c     d    " -> "a b c d "

func ReplaceNonAsciiChar

func ReplaceNonAsciiChar(s []byte, newchr byte) string

func ReplaceNonChineseChar

func ReplaceNonChineseChar(s string, newchr rune) string

*

包含中文和英文

func ReplaceNonPrintChar

func ReplaceNonPrintChar(s string, newchr rune) string

func ReplaceReg

func ReplaceReg(s string, regP string, new string) (string, error)

func ReverseBytes

func ReverseBytes(buf []byte)

*

abc=> cba

func RewriteFile

func RewriteFile(fileName string, fileData []byte) error

func RewriteFileFunc

func RewriteFileFunc(fileName string, fn func(w *os.File) error) error

func Round32

func Round32(f float32, n int) float32

func Round64

func Round64(f float64, n int) float64

func RoundTime_Second

func RoundTime_Second(t time.Time) time.Time

func SOD

func SOD(atime time.Time) float64

func SearchAFile

func SearchAFile(path string, currlevel, maxlevel int, comparefunc func(cmp, cur os.FileInfo, cmppath, curpath string) bool, onerr func(dirname string, err error) bool) (string, error)

*

  • 查找符合条件的第一个文件
  • comparefunc 返回true表示 cur比cmp文件更符合条件. cmp可能为空表示还没有查找到符合条件的文件, 判断时需要注意

func SearchAFileEx

func SearchAFileEx(path string, currlevel, maxlevel int, comparefunc func(cmp, cur os.FileInfo, cmppath, curpath string) bool, onerr func(dirname string, err error) bool) (string, os.FileInfo)

*

  • 查找符合条件的第一个文件
  • comparefunc 返回true表示 cur比cmp文件更符合条件. cmp可能为空表示还没有查找到符合条件的文件, 判断时需要注意

func SearchFiles

func SearchFiles(path string, currlevel, maxlevel int, comparefunc func(m, c os.FileInfo, mpath, cpath string) bool) (string, error)

func SecondBetween

func SecondBetween(t1, t2 time.Time) float64

func SecondOf

func SecondOf(start time.Time, end time.Time) int64

func SecondSub

func SecondSub(start, end time.Time) float64

func SetBitI32

func SetBitI32(buf []byte, startBitN int, l int, val int32)

func SetBitI64

func SetBitI64(buf []byte, startBitN int, l int, val int64)

func SetBitI8

func SetBitI8(buf []byte, startBitN int, l int, val int8)

func SetBitU16

func SetBitU16(buf []byte, startBitN int, l int, val uint16)

func SetBitU32

func SetBitU32(buf []byte, startBitN int, l int, val uint32)

func SetBitU64

func SetBitU64(buf []byte, startBitN int, l int, val uint64)

func SetBitU8

func SetBitU8(buf []byte, startBitN int, l int, val uint8)

func SetBitValue

func SetBitValue(ival uint64, bitN byte, bitVal bool) uint64

/ 设置位上的值 / SetBitValue(0, 2, true) = 二进制(10)

func SetBitValue0

func SetBitValue0(ival uint64, bitN byte, bitVal bool) uint64

/ 设置位上的值 0:位第一位 / SetBitValue(0, 1, true) = 二进制(10)

func SetU8BitValue0

func SetU8BitValue0(ival byte, bitN byte, bitVal bool) byte

/ 设置位上的值 0:位第一位 / SetU8BitValue0(0, 1, true) = 二进制(10)

func Size2GB

func Size2GB(sizebytes uint64) float64

func SizeStrToSize

func SizeStrToSize(str string) int64

**

SizeStrToSize("1024MB") SizeStrToSize("1024B")

func Split2PathAndFileName

func Split2PathAndFileName(fileName string) (dir string, name string)

*

路径最后带分隔符

func Split2Str

func Split2Str(s, sep string) (s1, s2 string)

func Split2StrV1

func Split2StrV1(s string, sep byte) (s1, s2 string)

func Split3Str

func Split3Str(s, sep string) (s1, s2, s3 string)

func SplitNumericAndRemain

func SplitNumericAndRemain(str string) (numstr, remain string)

func SplitQuantifiersUnits

func SplitQuantifiersUnits(s string) (qua string, unit string)

*

1个月  1, 个月
1 天   1,天

func SplitStrWidth

func SplitStrWidth(s string, width int) (rval []string)

func StartOfADay

func StartOfADay(day time.Time) time.Time

func StartOfAMonth

func StartOfAMonth(day time.Time) time.Time

func Str2lst

func Str2lst(s string, sep string, itmprefix, itmsuffix rune, tolower, emptyignore bool) []string

func StrIndex

func StrIndex(s string, strlst ...string) int

func StrIndexIgnoreCase

func StrIndexIgnoreCase(s string, strlst ...string) int

func StrNextSerialNo

func StrNextSerialNo(str string, maxl int, inc int) string

func StrTo3Float64

func StrTo3Float64(str string, sep string) (f1, f2, f3 float64)

func StrToFloat32Def

func StrToFloat32Def(s string, defval float32) float32

func StrToFloat64Def

func StrToFloat64Def(s string, defval float64) float64

func StrToInt64Def

func StrToInt64Def(s string, defval int64) int64

func StrToInt8Def

func StrToInt8Def(s string, defval int8) int8

func StrToInt8List

func StrToInt8List(str string, sep string) (rval []int8)

func StrToIntDef

func StrToIntDef(s string, defval int) int

func StrToInts

func StrToInts(str string, sep string) (rval []int)

func StrToNumSuffix

func StrToNumSuffix(str string, mult int64) int64

*

StrToNumSuffix("100K", 1024)
OK:
  1M, 100K, 1G, 15
FAIL:
  1KB, 1.4K 100m15k

func StrToTimeDef

func StrToTimeDef(str, format string, location *time.Location, def time.Time) time.Time

func StrToUInt8List

func StrToUInt8List(str string, sep string) (rval []byte)

func StringsRangeFunc

func StringsRangeFunc(strs []string, cb func(idx int64, elestr string) bool) (int64, error)

func SwapBytes

func SwapBytes(buf []byte) []byte

func SyncMapLength

func SyncMapLength(amap *sync.Map) int

func TimeBetween

func TimeBetween(t0 time.Time, start time.Time, end time.Time) bool

*

精确到毫秒

func TimeInLocalToday

func TimeInLocalToday(val time.Time) time.Duration

func TimeInUtcToday

func TimeInUtcToday(val time.Time) time.Duration

func TimeIsUnixZero

func TimeIsUnixZero(t time.Time) bool

**

判断t是否是Unix的起始时间或者之前.
返回为true表示该时间无效

func TimeString3

func TimeString3(val time.Time) string

func ToHourChr

func ToHourChr(atime time.Time) string

**

a:0时, f(a+6):6时, (a+23):23时,

func ToHourChrUpcase

func ToHourChrUpcase(atime time.Time) string

**

A:0时, F(A+6):6时, (A+23):23时,

func ToUTCTime

func ToUTCTime(src time.Time) time.Time

func TodayIDString

func TodayIDString() string

func TodayStr

func TodayStr() string

func Trim

func Trim(s string) string

func TrimPrefixBuf

func TrimPrefixBuf(buf []byte, prefix []byte) (rval []byte, changed bool)

func TrimPrefixBytes

func TrimPrefixBytes(buf []byte, byteset ...byte) []byte

func TrimRightByte

func TrimRightByte(buf []byte, rightByte byte) []byte

*

slice[:j]  // 从最开头切到 j(不包含 j)

func TrimRightBytes

func TrimRightBytes(buf []byte, rightByte ...byte) []byte

func TryCreateFileAndRenameIfFileExists

func TryCreateFileAndRenameIfFileExists(fileName string) (newfile *os.File, ret_err error)

*

  • 如果filename存在,
  • 尝试对filename进行重命名, 然后创建一个新的file
  • 如果重命名失败,则使用一个新的文件名

func TryStrToBool

func TryStrToBool(str string, def bool) bool

func TryStrToTime

func TryStrToTime(str string, location *time.Location, def time.Time) time.Time

func TryStrToTimeDefZero

func TryStrToTimeDefZero(str string, location *time.Location) (rval time.Time)

func UInt16_BEBytes

func UInt16_BEBytes(val uint16) []byte

func UInt16_FromBEBytes

func UInt16_FromBEBytes(buf []byte) uint16

func UInt16_FromLEBytes

func UInt16_FromLEBytes(buf []byte) uint16

func UInt16_LEBytes

func UInt16_LEBytes(val uint16) []byte

func UInt32_BEBytes

func UInt32_BEBytes(val uint32) []byte

func UInt32_FromBEBytes

func UInt32_FromBEBytes(buf []byte) uint32

func UInt32_LEBytes

func UInt32_LEBytes(val uint32) []byte

func UInt64_BEBytes

func UInt64_BEBytes(val uint64) []byte

**

0xAABBCCDDEEFF => 0000AABBCCDDEEFF

func UInt64_FromBEBytes

func UInt64_FromBEBytes(val []byte) uint64

func UInt8ListToStrs

func UInt8ListToStrs(lst []byte, sep string) string

func UnEscapeJSONStr

func UnEscapeJSONStr(bvalue []byte) []byte

func UnEscapeStr4Line

func UnEscapeStr4Line(str string) string

func WriteBuf_BE_Float64

func WriteBuf_BE_Float64(val float64, outBuf []byte)

func WriteBuf_LE_Float64

func WriteBuf_LE_Float64(val float64, outBuf []byte)

func XorBytes

func XorBytes(buf []byte) byte

Types

type BytesBuilder

type BytesBuilder struct {
	// contains filtered or unexported fields
}

func NewBytesBuilder

func NewBytesBuilder() *BytesBuilder

func (*BytesBuilder) AppendBufFromBase64Str

func (b *BytesBuilder) AppendBufFromBase64Str(base64str string) (int, error)

func (*BytesBuilder) AppendBuilder

func (b *BytesBuilder) AppendBuilder(b0 *BytesBuilder)

func (*BytesBuilder) AppendFixedStr

func (this *BytesBuilder) AppendFixedStr(s string, fixedw int, suffix string) *BytesBuilder

**

  • 添加 固定宽度的Buf, 如果字符串不够则后面补suffix, 如果超过长度则进行截取

func (*BytesBuilder) AppendFixedStrWithZeroByte

func (this *BytesBuilder) AppendFixedStrWithZeroByte(s string, fixedw int) *BytesBuilder

**

  • 添加 固定宽度的Buf, 如果字符串不够则后面补0, 如果超过长度则进行截取

func (*BytesBuilder) AppendIfNotEmpty

func (b *BytesBuilder) AppendIfNotEmpty(s string) *BytesBuilder

func (*BytesBuilder) AppendLine

func (b *BytesBuilder) AppendLine(s string) *BytesBuilder

func (*BytesBuilder) AppendRinexV

func (b *BytesBuilder) AppendRinexV(fv float64, digitN int, width int, zeroEmptyflag bool) *BytesBuilder

* [723994.1970]->[ 723994.1970]

func (*BytesBuilder) AppendStr

func (b *BytesBuilder) AppendStr(s string) *BytesBuilder

func (*BytesBuilder) AppendStrPrefixForWidth

func (b *BytesBuilder) AppendStrPrefixForWidth(s string, width int, prefix string) *BytesBuilder

func (*BytesBuilder) AppendStrSuffixForWidth

func (b *BytesBuilder) AppendStrSuffixForWidth(s string, width int, suffix string) *BytesBuilder

func (*BytesBuilder) AppendStrs

func (b *BytesBuilder) AppendStrs(strs ...string) *BytesBuilder

func (*BytesBuilder) AppendStrsWithSpliter

func (b *BytesBuilder) AppendStrsWithSpliter(spliter string, strs ...string) *BytesBuilder

func (*BytesBuilder) Appendf

func (b *BytesBuilder) Appendf(s string, args ...interface{}) *BytesBuilder

func (*BytesBuilder) Appendf_PrefixFixed

func (b *BytesBuilder) Appendf_PrefixFixed(w int, prefix string, s string, args ...interface{}) *BytesBuilder

func (*BytesBuilder) Base64String

func (b *BytesBuilder) Base64String() string

func (*BytesBuilder) BufAsHexStr

func (b *BytesBuilder) BufAsHexStr(start, l int, spliter string) string

func (*BytesBuilder) Buff

func (this *BytesBuilder) Buff(start, l int) []byte

func (*BytesBuilder) BuffEx

func (this *BytesBuilder) BuffEx(start, endidx int) []byte

func (*BytesBuilder) BuffTrimRight

func (this *BytesBuilder) BuffTrimRight(start, l int, rightBytes ...byte) []byte

func (*BytesBuilder) Byte

func (this *BytesBuilder) Byte(idx int) byte

func (*BytesBuilder) ByteOr

func (this *BytesBuilder) ByteOr(idx int, v byte) byte

func (*BytesBuilder) Bytes

func (this *BytesBuilder) Bytes() []byte

func (*BytesBuilder) Cap

func (b *BytesBuilder) Cap() int

Cap returns the capacity of the builder's underlying byte slice. It is the total space allocated for the string being built and includes any bytes already written.

func (*BytesBuilder) CheckSize

func (b *BytesBuilder) CheckSize(startidx int, l int)

func (*BytesBuilder) Cleanup

func (b *BytesBuilder) Cleanup()

**

Cleanup 只是清除数据, 内存块还是之前那块

func (*BytesBuilder) Clone

func (this *BytesBuilder) Clone() *BytesBuilder

func (*BytesBuilder) CloneBuf

func (this *BytesBuilder) CloneBuf() []byte

func (*BytesBuilder) CopyFrom

func (this *BytesBuilder) CopyFrom(src *BytesBuilder) *BytesBuilder

func (*BytesBuilder) Delete

func (this *BytesBuilder) Delete(startidx, n int) *BytesBuilder

**

func (*BytesBuilder) Delete2End

func (this *BytesBuilder) Delete2End(idx int) *BytesBuilder

func (*BytesBuilder) GetBitI

func (b *BytesBuilder) GetBitI(startidx int, startBitN, l int) int

** 按照大端法读取数据位作为返回值

func (*BytesBuilder) GetBitU

func (b *BytesBuilder) GetBitU(startidx int, startBitN, l int) uint32

** 按照大端法读取数据位作为返回值

func (*BytesBuilder) GetBitU16

func (b *BytesBuilder) GetBitU16(startidx int, startBitN, l int) uint16

func (*BytesBuilder) GetBitU64

func (b *BytesBuilder) GetBitU64(startidx int, startBitN, l int) uint64

** 按照大端法读取数据位作为返回值

func (*BytesBuilder) GetBitUAsInt

func (b *BytesBuilder) GetBitUAsInt(startidx int, startBitN, l int) int

func (*BytesBuilder) Grow

func (b *BytesBuilder) Grow(n int)

Grow grows b's capacity, if necessary, to guarantee space for another n bytes. After Grow(n), at least n bytes can be written to b without another allocation. If n is negative, Grow panics.

func (*BytesBuilder) HasSuffix

func (this *BytesBuilder) HasSuffix(suffix []byte) bool

func (*BytesBuilder) HexString

func (b *BytesBuilder) HexString(spliter string) string

func (*BytesBuilder) Index

func (this *BytesBuilder) Index(startidx int, sub []byte) int

func (*BytesBuilder) IndexByte

func (this *BytesBuilder) IndexByte(startidx int, v byte) int

func (*BytesBuilder) IndexFunc

func (this *BytesBuilder) IndexFunc(startidx int, fn func(v rune) bool) int

func (*BytesBuilder) Insert

func (this *BytesBuilder) Insert(startidx int, val []byte) *BytesBuilder

**

func (*BytesBuilder) InsertByte

func (this *BytesBuilder) InsertByte(startidx int, val byte) *BytesBuilder

**

func (*BytesBuilder) Len

func (b *BytesBuilder) Len() int

Len returns the number of accumulated bytes; b.Len() == len(b.StatusString()).

func (*BytesBuilder) Replace

func (this *BytesBuilder) Replace(startidx int, val []byte) *BytesBuilder

**

func (*BytesBuilder) ReplaceUInt16_BE

func (this *BytesBuilder) ReplaceUInt16_BE(startidx int, val uint16) *BytesBuilder

**

  • 大端法写入uint16

func (*BytesBuilder) ReplaceUInt16_LE

func (this *BytesBuilder) ReplaceUInt16_LE(startidx int, val uint16) *BytesBuilder

**

  • 小端法写入uint16

func (*BytesBuilder) ReplaceUInt32_BE

func (this *BytesBuilder) ReplaceUInt32_BE(startidx int, val uint32) *BytesBuilder

**

  • 大端法写入uint32

func (*BytesBuilder) ReplaceUInt32_LE

func (this *BytesBuilder) ReplaceUInt32_LE(startidx int, val uint32) *BytesBuilder

func (*BytesBuilder) Reset

func (b *BytesBuilder) Reset()

Reset resets the Builder to be empty. *

重置数据, 添加数据时会添加新的内存块

func (*BytesBuilder) SaveToFile

func (this *BytesBuilder) SaveToFile(fileName string) error

func (*BytesBuilder) SetBitI16

func (b *BytesBuilder) SetBitI16(startidx int, startBitN int, l int, val int16)

func (*BytesBuilder) SetBitI32

func (b *BytesBuilder) SetBitI32(startidx int, startBitN int, l int, val int32)

func (*BytesBuilder) SetBitI64

func (b *BytesBuilder) SetBitI64(startidx int, startBitN int, l int, val int64)

func (*BytesBuilder) SetBitU16

func (b *BytesBuilder) SetBitU16(startidx int, startBitN, l int, v uint16)

func (*BytesBuilder) SetBitU32

func (b *BytesBuilder) SetBitU32(startidx int, startBitN, l int, v uint32)

func (*BytesBuilder) SetBitU64

func (b *BytesBuilder) SetBitU64(startidx int, startBitN, l int, v uint64)

**

按照大端法写入数据

func (*BytesBuilder) SetBitU8

func (b *BytesBuilder) SetBitU8(startidx int, startBitN, l int, v byte)

func (*BytesBuilder) StatusString

func (b *BytesBuilder) StatusString() string

func (*BytesBuilder) Str2FixedBytes

func (this *BytesBuilder) Str2FixedBytes(s string, fixedw int) []byte

字符串到固定长度字符, 如果不够, 后面补0

func (*BytesBuilder) String

func (b *BytesBuilder) String() string

StatusString returns the accumulated string.

func (*BytesBuilder) UInt64_BE

func (this *BytesBuilder) UInt64_BE(val uint64) *BytesBuilder

**

  • 大端法写入uint64

func (*BytesBuilder) Uint16_BE

func (this *BytesBuilder) Uint16_BE(startidx int) uint16

**

  • 大端法读取uint16

func (*BytesBuilder) Uint16_LE

func (this *BytesBuilder) Uint16_LE(startidx int) uint16

**

  • 小端法读取uint16

func (*BytesBuilder) Uint32_BE

func (this *BytesBuilder) Uint32_BE(startidx int) uint32

**

  • 大端法读取uint32

func (*BytesBuilder) Uint32_LE

func (this *BytesBuilder) Uint32_LE(startidx int) uint32

**

  • 小端法读取uint32

func (*BytesBuilder) Uint64_BE

func (this *BytesBuilder) Uint64_BE(startidx int) uint64

**

  • 大端法读取uint32

func (*BytesBuilder) Write

func (b *BytesBuilder) Write(p []byte) (int, error)

Write appends the contents of p to b's buffer. Write always returns len(p), nil.

func (*BytesBuilder) WriteByte

func (b *BytesBuilder) WriteByte(c byte) error

WriteByte appends the byte c to b's buffer. The returned error is always nil.

func (*BytesBuilder) WriteBytes

func (b *BytesBuilder) WriteBytes(p ...byte)

func (*BytesBuilder) WriteRune

func (b *BytesBuilder) WriteRune(r rune) (int, error)

WriteRune appends the UTF-8 encoding of Unicode code point r to b's buffer. It returns the length of r and a nil error.

func (*BytesBuilder) WriteString

func (b *BytesBuilder) WriteString(s string) (int, error)

WriteString appends the contents of s to b's buffer. It returns the length of s and a nil error.

func (*BytesBuilder) WriteUInt16_BE

func (this *BytesBuilder) WriteUInt16_BE(val uint16) *BytesBuilder

**

  • 大端法写入uint16 最高有效字节在低位的方式称为大端法 Write_LE(0x0102) HexString : 01 02

func (*BytesBuilder) WriteUInt16_LE

func (this *BytesBuilder) WriteUInt16_LE(val uint16) *BytesBuilder

**

  • 小端法写入uint16
  • Write_LE(0x0102) HexString : 02 01

func (*BytesBuilder) WriteUInt32_BE

func (this *BytesBuilder) WriteUInt32_BE(val uint32) *BytesBuilder

**

  • 大端法写入uint32

func (*BytesBuilder) WriteUInt32_LE

func (this *BytesBuilder) WriteUInt32_LE(val uint32) *BytesBuilder

**

  • 小端法写入uint32

func (*BytesBuilder) WriteUInt64_BE

func (this *BytesBuilder) WriteUInt64_BE(val uint64) *BytesBuilder

**

  • 大端法写入uint64

func (*BytesBuilder) WriteWithHexStr

func (b *BytesBuilder) WriteWithHexStr(hexStr string, maxl int) int

type CacheFile

type CacheFile struct {
	// contains filtered or unexported fields
}

func NewCacheFile

func NewCacheFile(filename string, cachesize int) *CacheFile

func (*CacheFile) CheckOpen

func (this *CacheFile) CheckOpen() error

func (*CacheFile) Close

func (this *CacheFile) Close() error

func (*CacheFile) Flush

func (this *CacheFile) Flush()

func (*CacheFile) GetFileName added in v1.2.24013

func (this *CacheFile) GetFileName() string

func (*CacheFile) Write

func (this *CacheFile) Write(buf []byte) (int, error)

func (*CacheFile) WriteString

func (this *CacheFile) WriteString(s string) (int, error)

type ConnString added in v1.2.24041

type ConnString struct {
	Type string
	User string
	Pass string
	Addr string
	Path string
}

func ParseConnString added in v1.2.24041

func ParseConnString(str string) (rval ConnString)

func (*ConnString) Parse added in v1.2.24041

func (this *ConnString) Parse(str string)

func (ConnString) String added in v1.2.24041

func (this ConnString) String() string

type ConnectObjectRefStorage added in v1.2.24041

type ConnectObjectRefStorage struct {
	// contains filtered or unexported fields
}

连接对象管理, 借出去对象被+1, 归还-1 =0:释放

func NewConnectObjectRefStorage added in v1.2.24041

func NewConnectObjectRefStorage(newfun func(connstr string) interface{}) *ConnectObjectRefStorage

func (*ConnectObjectRefStorage) CheckGetRef added in v1.2.24041

func (this *ConnectObjectRefStorage) CheckGetRef(connstr string) *ObjectInnerRef

func (*ConnectObjectRefStorage) GetStatus added in v1.2.24041

func (this *ConnectObjectRefStorage) GetStatus(args ...string) string

func (*ConnectObjectRefStorage) Range added in v1.2.24041

func (this *ConnectObjectRefStorage) Range(filter func(obj interface{}) bool, lessfn func(iobj, jobj interface{}) bool, fn func(obj interface{}) bool)

func (*ConnectObjectRefStorage) ReleaseRef added in v1.2.24041

func (this *ConnectObjectRefStorage) ReleaseRef(itm *ObjectInnerRef)

type DElement

type DElement struct {

	// The DList to which this DElement belongs.
	DList *DList

	// The value stored with this DElement.
	Value interface{}
	// contains filtered or unexported fields
}

DElement is an DElement of a linked DList.

func (*DElement) Next

func (e *DElement) Next() *DElement

Next returns the next DList DElement or nil.

func (*DElement) Prev

func (e *DElement) Prev() *DElement

Prev returns the previous DList DElement or nil.

func (*DElement) RemoveFromDList

func (e *DElement) RemoveFromDList()

type DLinkNode

type DLinkNode struct {
	Value interface{}
	// contains filtered or unexported fields
}

func NewDlinknode

func NewDlinknode() *DLinkNode

func NewDlinknodeFromPool

func NewDlinknodeFromPool() *DLinkNode

func (*DLinkNode) Next

func (this *DLinkNode) Next() *DLinkNode
type DLinklist struct {
	// contains filtered or unexported fields
}
func NewDlinklist() *DLinklist

func (*DLinklist) Append

func (this *DLinklist) Append(node *DLinkNode)

*

  • 插入一个节点到尾部, 该节点的pre, next会被改变

func (*DLinklist) AppendValue

func (this *DLinklist) AppendValue(v interface{})

func (*DLinklist) Count

func (this *DLinklist) Count() int32

func (*DLinklist) FetchNext

func (this *DLinklist) FetchNext() *DLinkNode

func (*DLinklist) FetchPre

func (this *DLinklist) FetchPre() *DLinkNode

func (*DLinklist) First

func (this *DLinklist) First() *DLinkNode

*

  • 移除头部一个节点, 返回该节点, 如果为空返回nil

func (*DLinklist) InsertToFirst

func (this *DLinklist) InsertToFirst(node *DLinkNode)

*

  • 插入一个节点到头部, 该节点的pre, next会被改变

func (*DLinklist) List

func (this *DLinklist) List() []interface{}

func (*DLinklist) Nodes

func (this *DLinklist) Nodes() []*DLinkNode

func (*DLinklist) Range

func (this *DLinklist) Range(cb func(val interface{}) bool) int

*

  • 循环

func (*DLinklist) RangeEx

func (this *DLinklist) RangeEx(cb func(idx int, val interface{}, removeit *bool) bool, onremove func(node *DLinkNode)) int

*

  • 循环

func (*DLinklist) Remove

func (this *DLinklist) Remove(node *DLinkNode) bool

*

  • 移除一个元素,注意该元素必须是列表中的元素,否则 元素数量会出错

func (*DLinklist) RemoveFirst

func (this *DLinklist) RemoveFirst() *DLinkNode

*

  • 移除头部一个节点, 返回该节点, 如果为空返回nil

func (*DLinklist) RemoveLast

func (this *DLinklist) RemoveLast() *DLinkNode

*

  • 移除尾部一个节点, 返回该节点, 如果为空返回nil

func (*DLinklist) SeekFirst

func (this *DLinklist) SeekFirst() *DLinkNode

func (*DLinklist) SeekLast

func (this *DLinklist) SeekLast() *DLinkNode

type DList

type DList struct {
	// contains filtered or unexported fields
}

DList represents a doubly linked DList. The zero value for DList is an empty DList ready to use.

func NewDList

func NewDList() *DList

New returns an initialized DList.

func (*DList) Back

func (l *DList) Back() *DElement

Back returns the last DElement of DList l or nil.

func (*DList) Front

func (l *DList) Front() *DElement

Front returns the first DElement of DList l or nil.

func (*DList) Init

func (l *DList) Init() *DList

Init initializes or clears DList l.

func (*DList) InsertAfter

func (l *DList) InsertAfter(v interface{}, mark *DElement) *DElement

InsertAfter inserts a new DElement e with value v immediately after mark and returns e. If mark is not an DElement of l, the DList is not modified.

func (*DList) InsertBefore

func (l *DList) InsertBefore(v interface{}, mark *DElement) *DElement

InsertBefore inserts a new DElement e with value v immediately before mark and returns e. If mark is not an DElement of l, the DList is not modified.

func (*DList) Len

func (l *DList) Len() int

Len returns the number of DElements of DList l. The complexity is O(1).

func (*DList) MoveAfter

func (l *DList) MoveAfter(e, mark *DElement)

MoveAfter moves DElement e to its new position after mark. If e or mark is not an DElement of l, or e == mark, the DList is not modified.

func (*DList) MoveBefore

func (l *DList) MoveBefore(e, mark *DElement)

MoveBefore moves DElement e to its new position before mark. If e or mark is not an DElement of l, or e == mark, the DList is not modified.

func (*DList) MoveToBack

func (l *DList) MoveToBack(e *DElement)

MoveToBack moves DElement e to the back of DList l. If e is not an DElement of l, the DList is not modified.

func (*DList) MoveToFront

func (l *DList) MoveToFront(e *DElement)

MoveToFront moves DElement e to the front of DList l. If e is not an DElement of l, the DList is not modified.

func (*DList) PushBack

func (l *DList) PushBack(v interface{}) *DElement

PushBack inserts a new DElement e with value v at the back of DList l and returns e.

func (*DList) PushBackDList

func (l *DList) PushBackDList(other *DList)

PushBackDList inserts a copy of an other DList at the back of DList l. The DLists l and other may be the same.

func (*DList) PushFront

func (l *DList) PushFront(v interface{}) *DElement

PushFront inserts a new DElement e with value v at the front of DList l and returns e.

func (*DList) PushFrontDList

func (l *DList) PushFrontDList(other *DList)

PushFrontDList inserts a copy of an other DList at the front of DList l. The DLists l and other may be the same.

func (*DList) Remove

func (l *DList) Remove(e *DElement) interface{}

Remove removes e from l if e is an DElement of DList l. It returns the DElement value e.Value.

type DiskStatus

type DiskStatus struct {
	All  uint64 `json:"all"`
	Used uint64 `json:"used"`
	Free uint64 `json:"free"`
}

func (DiskStatus) FreePercent

func (this DiskStatus) FreePercent() float64

* 返回小数 0.1 = 10%

func (DiskStatus) FreePercentStr

func (this DiskStatus) FreePercentStr(n int) string

type EscapeError

type EscapeError string

func (EscapeError) Error

func (e EscapeError) Error() string

type IStatusGet added in v1.2.24041

type IStatusGet interface {
	GetStatus(args StrMap) string
}

type InvalidHostError

type InvalidHostError string

func (InvalidHostError) Error

func (e InvalidHostError) Error() string

type ObjectInnerRef added in v1.2.24041

type ObjectInnerRef struct {
	// contains filtered or unexported fields
}

func (*ObjectInnerRef) GetObject added in v1.2.24041

func (this *ObjectInnerRef) GetObject() interface{}

type ReadFileSession

type ReadFileSession struct {
	// contains filtered or unexported fields
}

func NewReadFileSession

func NewReadFileSession(filename string) *ReadFileSession

func (*ReadFileSession) Close

func (this *ReadFileSession) Close() error

func (*ReadFileSession) CloseFlag

func (this *ReadFileSession) CloseFlag() int8

func (*ReadFileSession) ErrFlag

func (this *ReadFileSession) ErrFlag() int8

func (*ReadFileSession) Read

func (this *ReadFileSession) Read(b []byte) (n int, err error)

func (*ReadFileSession) Reset

func (this *ReadFileSession) Reset()

type StrMap

type StrMap map[string]string

func NewStrMap

func NewStrMap() StrMap

func NewStrMapEx

func NewStrMapEx(s, kvsep, itmsep string) StrMap

func NewStrMapFromURLStr added in v1.2.24041

func NewStrMapFromURLStr(s string) StrMap

func (StrMap) CopyFrom

func (this StrMap) CopyFrom(src StrMap)

func (StrMap) Encode

func (this StrMap) Encode(kvspliter string, itmspliter string) string

func (StrMap) ExecReplace

func (this StrMap) ExecReplace(s string) string

ExecReplace 利用映射关系进行替换, key -> value

func (StrMap) Float64ByName

func (this StrMap) Float64ByName(k string, def float64) float64

func (StrMap) Int16ByName

func (this StrMap) Int16ByName(k string, def int16) int16

func (StrMap) Int8ByName

func (this StrMap) Int8ByName(k string, def int8) int8

func (StrMap) IntByName

func (this StrMap) IntByName(k string, def int) int

func (StrMap) ParseCmdArgs

func (this StrMap) ParseCmdArgs(args []string)

解析命令行 XX.exe -a=v

func (StrMap) ParseKVPairs

func (this StrMap) ParseKVPairs(s string, kvsep string, itmsep string)

func (StrMap) ParseKVPairsEx

func (this StrMap) ParseKVPairsEx(s string, kvsep string, itmsep string, keylower bool)

func (StrMap) Reset

func (this StrMap) Reset()

func (StrMap) SortRange

func (this StrMap) SortRange(fn func(k, v string) bool)

func (StrMap) SortRangeEncode

func (this StrMap) SortRangeEncode(kvspliter string, itmspliter string, fn func(k, v string) bool) string

func (StrMap) StringByName

func (this StrMap) StringByName(k string, def string) string

func (StrMap) U8ByName

func (this StrMap) U8ByName(k string, def byte) byte

func (StrMap) URLFormDecode

func (this StrMap) URLFormDecode(s string)

func (StrMap) URLFormEncode

func (this StrMap) URLFormEncode() string

func (StrMap) UnixTimeByName

func (this StrMap) UnixTimeByName(k string, def time.Time) time.Time

type SyncMap

type SyncMap struct {
	// contains filtered or unexported fields
}

*

  • 可以单独使用

func (*SyncMap) AsInt32

func (this *SyncMap) AsInt32(id interface{}, def int32) int32

func (*SyncMap) AsString

func (this *SyncMap) AsString(id interface{}, def string) string

func (*SyncMap) BatchSetFromStr

func (this *SyncMap) BatchSetFromStr(str string)

*

k=v;k=v;

func (*SyncMap) Clear

func (this *SyncMap) Clear()

func (*SyncMap) Contain

func (this *SyncMap) Contain(id interface{}) bool

func (*SyncMap) Count

func (this *SyncMap) Count() int

func (*SyncMap) CountFunc

func (this *SyncMap) CountFunc(fn func(k, v interface{}) bool) int

func (*SyncMap) Get

func (this *SyncMap) Get(id interface{}, def interface{}) interface{}

func (*SyncMap) List

func (this *SyncMap) List() []interface{}

func (*SyncMap) ListEx

func (this *SyncMap) ListEx(filter func(key, value interface{}) bool, less_sortfunc func(iItm, jItm interface{}) bool) []interface{}

func (*SyncMap) ListRangeV2

func (this *SyncMap) ListRangeV2(filter func(key, value interface{}) bool,
	less_sortfunc func(k0, v0, k1, v1 interface{}) bool,
	rangfn func(key, val interface{}) bool)

func (*SyncMap) ListRangeV3

func (this *SyncMap) ListRangeV3(filterflag, sortflag int, filter func(key, value interface{}) bool,
	less_sortfunc func(k0, v0, k1, v1 interface{}) bool,
	rangfn func(key, val interface{}) bool)

func (*SyncMap) ListSorted

func (this *SyncMap) ListSorted(lessfunc func(iItm, jItm interface{}) bool) []interface{}

func (*SyncMap) LoadOrStore

func (this *SyncMap) LoadOrStore(id interface{}, store interface{}) (actual interface{}, loaded bool)

func (*SyncMap) LoadOrStoreFunc

func (this *SyncMap) LoadOrStoreFunc(id interface{}, newfunc func() interface{},
	freefunc func(val interface{})) (actual interface{})

func (*SyncMap) LoadOrStoreFunc2

func (this *SyncMap) LoadOrStoreFunc2(id interface{}, newfunc func() interface{},
	freefunc func(val interface{})) (actual interface{}, loaded bool)

func (*SyncMap) PickFirst

func (this *SyncMap) PickFirst(filter func(key, value interface{}) bool, less_sortfunc func(iItm, jItm interface{}) bool) interface{}

func (*SyncMap) Range

func (this *SyncMap) Range(f func(key, value interface{}) bool)

func (*SyncMap) Remove

func (this *SyncMap) Remove(id interface{})

func (*SyncMap) RemoveAndGet

func (this *SyncMap) RemoveAndGet(id interface{}) (val interface{}, ok bool)

func (*SyncMap) RemoveEx

func (this *SyncMap) RemoveEx(id interface{}) bool

func (*SyncMap) Set

func (this *SyncMap) Set(id interface{}, val interface{})

func (*SyncMap) Store

func (this *SyncMap) Store(id interface{}, val interface{})

func (*SyncMap) ValAsString

func (this *SyncMap) ValAsString(spliter string, filter func(key, value interface{}) bool, less_sortfunc func(iItm, jItm interface{}) bool) string

func (*SyncMap) ValAsString2

func (this *SyncMap) ValAsString2(spliter string, filter func(key, value interface{}) bool, ordertype int) string

**

ordertype 0:顺序, 1:倒序

type SyncQueue

type SyncQueue struct {
	// contains filtered or unexported fields
}

func NewSyncQueue

func NewSyncQueue() *SyncQueue

func (*SyncQueue) Count

func (this *SyncQueue) Count() int32

func (*SyncQueue) Peek

func (this *SyncQueue) Peek() (bool, interface{})

*

  • Peek第一个

func (*SyncQueue) Pop

func (this *SyncQueue) Pop() (bool, interface{})

*

  • 弹出第一个

func (*SyncQueue) PopTaskArgMaxFunc

func (this *SyncQueue) PopTaskArgMaxFunc(max int, cb func(args interface{}) bool) int

*

  • 取多个任务, 一般在回调中执行

func (*SyncQueue) Push

func (this *SyncQueue) Push(val interface{})

func (*SyncQueue) Range

func (this *SyncQueue) Range(cb func(idx int, value interface{}, removeit *bool) bool)

**

先获取所有的节点后, 再进行遍历, 避免产生死锁

func (*SyncQueue) Reset

func (this *SyncQueue) Reset()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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