txtk

package module
v0.0.0-...-7d2d0e6 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2019 License: MIT Imports: 26 Imported by: 4

README

txtk

Go语言(Golang)的常用工具函数包,用于研究和教学等。其中tx是作者"TopXeQ"的简写,tk是“toolkit”的简写。

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DebugModeG bool = false
View Source
var TXTimeFormatCompact = "20060102150405"

Functions

func AESDecrypt

func AESDecrypt(src, key []byte) ([]byte, error)

func AESEncrypt

func AESEncrypt(src, key []byte) ([]byte, error)

func AddDebug

func AddDebug(strA string)

func AddDebugF

func AddDebugF(formatA string, argsA ...interface{})

func AddLastSubString

func AddLastSubString(strA string, subStrA string) string

func AnalyzeCommandLineParamter

func AnalyzeCommandLineParamter(cmdLineA string) []string

AnalyzeCommandLineParamter 分解命令行参数,注意如果要带双引号,需要从开始到结束都括上,例如save "-fileName=abc.txt",而不是save -fileName="abc.txt"

func AnalyzeURLParams

func AnalyzeURLParams(strA string) map[string]string

func AppendDualLineList

func AppendDualLineList(listA [][]string, fileNameA string) string

func AppendSimpleMapFromFile

func AppendSimpleMapFromFile(mapA map[string]string, fileNameA string) string

func AppendStringToFile

func AppendStringToFile(strA string, fileA string) string

func ByteToHex

func ByteToHex(byteA byte) string

func CalCosineSimilarityBetweenFloatsBig

func CalCosineSimilarityBetweenFloatsBig(f1, f2 []float64) float64

func ClearDebug

func ClearDebug()

func ContainsInStringList

func ContainsInStringList(strA string, strListA []string) bool

func ConvertToGB18030

func ConvertToGB18030(srcA string) string

ConvertToGB18030 转换UTF-8字符串为GB18030编码

func ConvertToGB18030Bytes

func ConvertToGB18030Bytes(srcA string) []byte

ConvertToGB18030Bytes 转换UTF-8字符串为GB18030编码的字节切片

func ConvertToUTF8

func ConvertToUTF8(srcA []byte, srcEncA string) string

ConvertToUTF8 转换GB18030编码等字符串为UTF-8字符串

func DecodeStringSimple

func DecodeStringSimple(s string) string

func DeleteItemInInt64Array

func DeleteItemInInt64Array(aryA []int64, idxA int64) []int64

func DeleteItemInIntArray

func DeleteItemInIntArray(aryA []int, idxA int) []int

DeleteItemInIntArray 删除字符串切片中的某一项

func DeleteItemInStringArray

func DeleteItemInStringArray(aryA []string, idxA int) []string

DeleteItemInStringArray 删除字符串切片中的某一项

func DownloadPage

func DownloadPage(urlA string, originalEncodingA string, postDataA url.Values, customHeaders string, timeoutSecsA time.Duration) string

DownloadPage download page with any encoding and convert to UTF-8

func DownloadPageUTF8

func DownloadPageUTF8(urlA string, postDataA url.Values, customHeaders string, timeoutSecsA time.Duration) string

func EncodeStringSimple

func EncodeStringSimple(strA string) string

func EndsWith

func EndsWith(strA string, subStrA string) bool

EndsWith 检查字符串strA结尾是否是subStrA

func EnsureMakeDirs

func EnsureMakeDirs(pathA string) string

func EnsureValidFileNameX

func EnsureValidFileNameX(fileNameA string) string

EnsureValidFileNameX 确保文件名合理并且长度合适

func FindFirstDiffIndex

func FindFirstDiffIndex(strA string, str2A string) int

func FindSamePrefix

func FindSamePrefix(strA, str2A string) string

func Float32ArrayToFloat64Array

func Float32ArrayToFloat64Array(aryA []float32) []float64

func Float64ToStr

func Float64ToStr(floatA float64) string

func GenerateErrorString

func GenerateErrorString(errStrA string) string

GenerateErrorString 生成一个出错字符串

func GenerateErrorStringF

func GenerateErrorStringF(formatA string, argsA ...interface{}) string

GenerateErrorStringF 生成一个出错字符串,但可以加上格式,类似Printf

func GenerateFileListRecursively

func GenerateFileListRecursively(dirA string, patternA string) []string

func GenerateJSONPResponse

func GenerateJSONPResponse(statusA string, valueA string, reqA *http.Request) string

func GenerateJSONPResponseWithObject

func GenerateJSONPResponseWithObject(statusA string, valueA string, objectA string, reqA *http.Request) string

func GetApplicationPath

func GetApplicationPath() string

func GetDebug

func GetDebug() string

func GetDirOfFilePath

func GetDirOfFilePath(pathA string) string

func GetErrorString

func GetErrorString(errStrA string) string

GetErrorString 获取出错字符串中的出错原因部分

func GetFileExt

func GetFileExt(filePathA string) string

func GetFilePathSeperator

func GetFilePathSeperator() string

func GetFormValueWithDefaultValue

func GetFormValueWithDefaultValue(reqA *http.Request, keyA string, defaultA string) string

func GetGlobalEnvList

func GetGlobalEnvList() []string

func GetGlobalEnvString

func GetGlobalEnvString() string

func GetInputBufferedScan

func GetInputBufferedScan() string

GetInputBufferedScan 获取键盘输入

func GetLastComponentOfFilePath

func GetLastComponentOfFilePath(pathA string) string

func GetNowDateString

func GetNowDateString() string

GetNowDateString output likes 20150409

func GetNowTimeOnlyStringBeijing

func GetNowTimeOnlyStringBeijing() string

func GetNowTimeString

func GetNowTimeString() string

GetNowTimeString GetNowTimeString

func GetNowTimeStringFormal

func GetNowTimeStringFormal() string

func GetNowTimeStringHourMinute

func GetNowTimeStringHourMinute() string

func GetOSName

func GetOSName() string

func GetParameterByIndexWithDefaultValue

func GetParameterByIndexWithDefaultValue(argsA []string, idxA int, defaultA string) string

GetParameterByIndexWithDefaultValue 按顺序序号获取命令行参数,其中0代表第一个参数,也就是软件名称或者命令名称,1开始才是第一个参数,注意参数不包括开关,即类似-verbose=true这样的

func GetRandomInt64InRange

func GetRandomInt64InRange(minA int64, maxA int64) int64

func GetRandomInt64LessThan

func GetRandomInt64LessThan(maxA int64) int64

func GetRandomIntInRange

func GetRandomIntInRange(minA int, maxA int) int

GetRandomIntInRange 获取[minA-maxA]之间的随机数

func GetRandomIntLessThan

func GetRandomIntLessThan(maxA int) int

GetRandomIntLessThan 获取[0-maxA)之间的随机数

func GetRandomSubDualList

func GetRandomSubDualList(listA [][]string, countA int) [][]string

func GetRandomizeInt64ArrayCopy

func GetRandomizeInt64ArrayCopy(aryA []int64) []int64

func GetRandomizeIntArrayCopy

func GetRandomizeIntArrayCopy(aryA []int) []int

GetRandomizeIntArrayCopy 获得一个随机化顺序后的int数组

func GetRandomizeStringArrayCopy

func GetRandomizeStringArrayCopy(aryA []string) []string

GetRandomizeStringArrayCopy 获得一个随机化后的字符串数组

func GetRuntimeStack

func GetRuntimeStack() string

func GetSuccessValue

func GetSuccessValue(strA string) string

func GetSwitchWithDefaultInt64Value

func GetSwitchWithDefaultInt64Value(argsA []string, switchStrA string, defaultA int64) int64

func GetSwitchWithDefaultIntValue

func GetSwitchWithDefaultIntValue(argsA []string, switchStrA string, defaultA int) int

GetSwitchWithDefaultIntValue 与GetSwitchWithDefaultValue类似,返回一个整数

func GetSwitchWithDefaultValue

func GetSwitchWithDefaultValue(argsA []string, switchStrA string, defaultA string) string

GetSwitchWithDefaultValue 获取命令行参数中的开关,用法:tmps := tk.GetSwitchWithDefaultValue(args, "-verbose=", "false")

func HasGlobalEnv

func HasGlobalEnv(vA string) bool

func IfFileExists

func IfFileExists(fileNameA string) bool

IfFileExists 判断文件是否存在

func IfSwitchExists

func IfSwitchExists(argsA []string, switchStrA string) bool

IfSwitchExists 判断命令行参数中是否存在开关,用法:flag := IfSwitchExists(args, "-restart")

func InStrings

func InStrings(strA string, argsA ...string) bool

func IndexInStringList

func IndexInStringList(strA string, strListA []string) int

func IndexInStringListFromEnd

func IndexInStringListFromEnd(strA string, strListA []string) int

func Int64ArrayToFloat64Array

func Int64ArrayToFloat64Array(aryA []int64) []float64

func Int64ToStr

func Int64ToStr(intA int64) string

func IntToStr

func IntToStr(intA int) string

IntToStr 整形转字符串

func IsDirectory

func IsDirectory(dirNameA string) bool

IsDirectory if is directory

func IsEmptyTrim

func IsEmptyTrim(strA string) bool

func IsErrorString

func IsErrorString(errStrA string) bool

IsErrorString 判断是否表示出错的字符串

func IsFile

func IsFile(fileNameA string) bool

IsFile if is file

func JSONToMapStringString

func JSONToMapStringString(objStrA string) map[string]string

func JoinDualList

func JoinDualList(listA [][]string, sepItemA, sepInItemA string, withLineNumberA bool) string

func JoinLines

func JoinLines(strListA []string) string

func JoinLinesBySeparator

func JoinLinesBySeparator(strListA []string, sepA string) string

func Len64

func Len64(aryA []string) int64

Len64 返回int64结果的len

func LoadBytes

func LoadBytes(fileNameA string, numA int) []byte

LoadBytes LoadBytes

func LoadDualLineList

func LoadDualLineList(fileNameA string) ([][]string, string)

func LoadDualLineListFromString

func LoadDualLineListFromString(strA string) [][]string

func LoadSimpleMapFromDir

func LoadSimpleMapFromDir(dirA string) map[string]string

func LoadSimpleMapFromFile

func LoadSimpleMapFromFile(fileNameA string) map[string]string

func LoadStringFromFile

func LoadStringFromFile(fileNameA string) string

LoadStringFromFile 从文件中读取整个内容到字符串中

func LoadStringList

func LoadStringList(fileNameA string) ([]string, string)

func LogWithTime

func LogWithTime(formatA string, argsA ...interface{})

func MD5Encrypt

func MD5Encrypt(strA string) string

func NowToFileName

func NowToFileName() string

func ObjectToJSON

func ObjectToJSON(objA interface{}) string

ObjectToJSON 任意对象转换为JSON字符串

func ObjectToJSONIndent

func ObjectToJSONIndent(objA interface{}) string

func Pkcs7Padding

func Pkcs7Padding(ciphertext []byte, blockSize int) []byte

func Pl

func Pl(formatA string, argsA ...interface{})

Pl 类似Pr,但结尾会加有一个回车

func PlAndExit

func PlAndExit(formatA string, argsA ...interface{})

func PlErr

func PlErr(errA error)

func PlErrAndExit

func PlErrAndExit(errA error)

func PlErrSimple

func PlErrSimple(formatA string, argsA ...interface{})

PrlErrSimple 输出错误信息,结尾加一个回车

func PlErrSimpleAndExit

func PlErrSimpleAndExit(formatA string, argsA ...interface{})

func PlSimpleErrorString

func PlSimpleErrorString(strA string)

func PlTXErr

func PlTXErr(strA string)

func Plv

func Plv(argsA ...interface{})

func PlvWithError

func PlvWithError(vA interface{}, errStrA string)

func PostRequest

func PostRequest(urlA, reqBodyA string, timeoutSecsA time.Duration) (string, error)

PostRequest : another POST request sender

func Pr

func Pr(argsA ...interface{})

Pr 即fmt.Print

func Prf

func Prf(formatA string, argsA ...interface{})

Prf 仅仅是封装了fmt.Printf函数

func Printf

func Printf(format string, a ...interface{})

Printf 仅仅封装了fmt.Printf函数,与其完全一致

func Printfln

func Printfln(format string, a ...interface{})

Printfln 仅仅封装了fmt.Printf函数,但结尾会多输出一个换行符

func Randomize

func Randomize()

Randomize 初始化随机数种子

func RegContains

func RegContains(strA, patternA string) bool

func RegFindAll

func RegFindAll(strA, patternA string, groupA int) []string

func RegFindFirst

func RegFindFirst(strA, patternA string, groupA int) string

func RegMatch

func RegMatch(strA, patternA string) bool

func RegReplace

func RegReplace(strA, patternA, replaceA string) string

func RemoveDuplicateInDualLineList

func RemoveDuplicateInDualLineList(listA [][]string) [][]string

func RemoveFileExt

func RemoveFileExt(filePathA string) string

func RemoveGlobalEnv

func RemoveGlobalEnv(vA string)

func RemoveLastSubString

func RemoveLastSubString(strA string, subStrA string) string

func Replace

func Replace(strA, findA, replaceA string) string

func ReplaceLineEnds

func ReplaceLineEnds(strA string, replacementA string) string

func RestoreLineEnds

func RestoreLineEnds(strA string, replacementA string) string

func SaveDualLineList

func SaveDualLineList(listA [][]string, fileNameA string) string

func SaveSimpleMapToFile

func SaveSimpleMapToFile(mapA map[string]string, fileA string) string

func SaveStringList

func SaveStringList(strListA []string, fileA string) string

func SaveStringListWin

func SaveStringListWin(strListA []string, fileA string) string

func SaveStringToFile

func SaveStringToFile(strA string, fileA string) string

SaveStringToFile 保存字符串到文件

func SetGlobalEnv

func SetGlobalEnv(vA string)

func SetLogFile

func SetLogFile(fileNameA string)

func ShuffleStringArray

func ShuffleStringArray(aryA []string, timesA int)

ShuffleStringArray 把字符串数组随机化打乱timesA次

func SleepMilliSeconds

func SleepMilliSeconds(msA int)

func SleepSeconds

func SleepSeconds(secA int)

func Split

func Split(strA string, sepA string) []string

func SplitLines

func SplitLines(strA string) []string

func SplitLinesRemoveEmpty

func SplitLinesRemoveEmpty(strA string) []string

func SplitN

func SplitN(strA string, sepA string, countA int) []string

func Spr

func Spr(formatA string, argsA ...interface{}) string

Spr 仅仅是封装了fmt.Sprintf函数

func StartsWith

func StartsWith(strA string, subStrA string) bool

StartsWith 检查字符串strA开始是否是subStrA

func StartsWithDigit

func StartsWithDigit(strA string) bool

func StartsWithIgnoreCase

func StartsWithIgnoreCase(strA string, subStrA string) bool

func StartsWithUpper

func StartsWithUpper(wordA string) bool

func StrToBool

func StrToBool(strA string) bool

func StrToFloat64WithDefaultValue

func StrToFloat64WithDefaultValue(strA string, defaultA float64) float64

func StrToInt64WithDefaultValue

func StrToInt64WithDefaultValue(strA string, defaultA int64) int64

func StrToIntPositive

func StrToIntPositive(strA string) int

func StrToIntWithDefaultValue

func StrToIntWithDefaultValue(strA string, defaultA int) int

StrToIntWithDefaultValue 字符串转扎整数,如果有问题则返回默认数值

func StrToTimeCompact

func StrToTimeCompact(strA string, defaultA time.Time) time.Time

func StrToTimeCompactNoError

func StrToTimeCompactNoError(strA string) time.Time

func StringReplace

func StringReplace(strA string, argsA ...string) string

func Trim

func Trim(strA string) string

Trim 仅仅封装了strings.TrimSpace

func TrimCharSet

func TrimCharSet(strA string, charSetA string) string

Types

type ExitCallback

type ExitCallback func()

type RandomX

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

RandomX 是一个线程不安全的随机数产生器

func NewRandomGenerator

func NewRandomGenerator() *RandomX

func (*RandomX) Float64

func (p *RandomX) Float64() float64

func (*RandomX) Int

func (p *RandomX) Int() int

func (*RandomX) Int64

func (p *RandomX) Int64() int64

func (*RandomX) Int64N

func (p *RandomX) Int64N(maxA int64) int64

func (*RandomX) Randomize

func (p *RandomX) Randomize()

type SimpleEvent

type SimpleEvent struct {
	Type  string
	Value string
}

SimpleEvent 简捷的事件结构

func CreateSimpleEvent

func CreateSimpleEvent(typeA string, valueA string) *SimpleEvent

CreateSimpleEvent 创建一个SimpleEvent对象,并为其赋初值

func (*SimpleEvent) Init

func (p *SimpleEvent) Init(typeA string, valueA string)

Init 为SimpleEvent初始化数据

type TXCollection

type TXCollection struct {
	Content map[string]int
}
var GlobalEnvSetG *TXCollection = nil

func CreateTXCollection

func CreateTXCollection(sizeA int) *TXCollection

func (*TXCollection) AddOrSet

func (p *TXCollection) AddOrSet(strA string)

func (*TXCollection) AddOrSetExcludeEmpty

func (p *TXCollection) AddOrSetExcludeEmpty(strA string)

func (*TXCollection) Contains

func (p *TXCollection) Contains(strA string) bool

func (*TXCollection) GetList

func (p *TXCollection) GetList() []string

func (*TXCollection) GetListString

func (p *TXCollection) GetListString(ifUpA bool, sepA string) string

func (*TXCollection) GetSortedList

func (p *TXCollection) GetSortedList(ifUpA bool) []string

func (*TXCollection) InitX

func (p *TXCollection) InitX(sizeA int)

func (*TXCollection) Length

func (p *TXCollection) Length() int

func (*TXCollection) Remove

func (p *TXCollection) Remove(strA string) bool

func (*TXCollection) Size

func (p *TXCollection) Size() int

type TXResult

type TXResult struct {
	Status string
	Value  string
}

存放TX格式的网络API返回结果

func TXResultFromString

func TXResultFromString(strA string) (*TXResult, error)

type TXString

type TXString struct {
	Err string
	Obj interface{}
	// contains filtered or unexported fields
}

func CreateString

func CreateString(strA string, errA string) *TXString

func CreateStringEmpty

func CreateStringEmpty() *TXString

func CreateStringError

func CreateStringError(errA string) *TXString

func CreateStringErrorF

func CreateStringErrorF(formatA string, argsA ...interface{}) *TXString

func CreateStringErrorFromTXError

func CreateStringErrorFromTXError(errA string) *TXString

func CreateStringSimple

func CreateStringSimple(strA string) *TXString

func CreateStringSuccess

func CreateStringSuccess() *TXString

func CreateStringWithObject

func CreateStringWithObject(strA string, objA interface{}) *TXString

func GenerateErrorStringFTX

func GenerateErrorStringFTX(formatA string, argsA ...interface{}) *TXString

func GenerateErrorStringTX

func GenerateErrorStringTX(errStrA string) *TXString

func LoadStringTX

func LoadStringTX(fileNameA string) *TXString

func RegFindFirstTX

func RegFindFirstTX(strA, patternA string, groupA int) *TXString

func (*TXString) Contains

func (p *TXString) Contains(patternA string) bool

func (*TXString) ContainsInHtmlAttributeString

func (p *TXString) ContainsInHtmlAttributeString(substrA string) bool

func (*TXString) CutToLen

func (p *TXString) CutToLen(lenA int) string

func (*TXString) EQ

func (p *TXString) EQ(strA string) bool

func (*TXString) EndsWith

func (p *TXString) EndsWith(strA string) bool

func (*TXString) Equals

func (p *TXString) Equals(strA string) bool

func (*TXString) EqualsIgnoreCase

func (p *TXString) EqualsIgnoreCase(strA string) bool

func (*TXString) Error

func (p *TXString) Error() string

func (*TXString) ErrorString

func (p *TXString) ErrorString() string

func (*TXString) ErrorStringF

func (p *TXString) ErrorStringF(formatA string) string

func (*TXString) InitWithString

func (p *TXString) InitWithString(strA string) *TXString

func (*TXString) IsEmpty

func (p *TXString) IsEmpty() bool

func (*TXString) IsEmptyTrim

func (p *TXString) IsEmptyTrim() bool

func (*TXString) IsError

func (p *TXString) IsError() bool

func (*TXString) JSONString

func (p *TXString) JSONString() string

func (*TXString) Length

func (p *TXString) Length() int

func (*TXString) List

func (p *TXString) List() []string

func (*TXString) PlErr

func (p *TXString) PlErr(prefixA string) *TXString

func (*TXString) PlSuccessOrErr

func (p *TXString) PlSuccessOrErr(workA string) *TXString

func (*TXString) Print

func (p *TXString) Print()

func (*TXString) PrintResultWithTimeLast

func (p *TXString) PrintResultWithTimeLast()

func (*TXString) PrintWithPrefixTime

func (p *TXString) PrintWithPrefixTime(prefixA string)

func (*TXString) PrintWithPrefixTimeLast

func (p *TXString) PrintWithPrefixTimeLast(prefixA string)

func (*TXString) PrintWithTimeLast

func (p *TXString) PrintWithTimeLast()

func (*TXString) RegFindAll

func (p *TXString) RegFindAll(patternA string, groupA int) []string

func (*TXString) RegFindFirst

func (p *TXString) RegFindFirst(patternA string, groupA int) string

func (*TXString) RegReplace

func (p *TXString) RegReplace(patternA string, replacementA string) *TXString

func (*TXString) Replace

func (p *TXString) Replace(patternA string, replacementA string) *TXString

func (*TXString) Save

func (p *TXString) Save(fileA string) *TXString

func (*TXString) Set

func (p *TXString) Set(strA string) *TXString

func (*TXString) SplitLines

func (p *TXString) SplitLines() []string

func (*TXString) StartsWith

func (p *TXString) StartsWith(strA string) bool

func (*TXString) String

func (p *TXString) String() string

func (*TXString) StringEmptyIfError

func (p *TXString) StringEmptyIfError() string

func (*TXString) ToStringList

func (p *TXString) ToStringList() []string

func (*TXString) ToStringListRemoveEmpty

func (p *TXString) ToStringListRemoveEmpty() []string

func (*TXString) Trim

func (p *TXString) Trim() *TXString

type TXStringArray

type TXStringArray []string

func (TXStringArray) Contains

func (aryM TXStringArray) Contains(strA string) bool

func (TXStringArray) ContainsIgnoreCase

func (aryM TXStringArray) ContainsIgnoreCase(strA string) bool

type TXStringSlice

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

Jump to

Keyboard shortcuts

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