doraemon

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert added in v0.2.0

func Assert(ok bool)

func AssertEqual added in v0.2.0

func AssertEqual[T comparable](t1, t2 T, tn ...T)

func AssertError added in v0.2.0

func AssertError(err error)

func BytesAsPointer

func BytesAsPointer(b []byte) (unsafe.Pointer, int, int)

func BytesToString

func BytesToString(b []byte) string

BytesToString converts a byte slice to a string without copying. The byte slice must not be modified after the conversion. otherwise, the string may be corrupted.

func CharToInt

func CharToInt(c byte) int

字符转整型

func Compress

func Compress(file []string, zipFile string) error

Compress compresses the file to the zip file.

func CopyDir

func CopyDir(src, dst string, overwrite bool) error

复制文件夹到指定目录

overwrite为true时,如果目标文件夹存在名字相同的文件则覆盖, overwrite为false时,如果目标文件存在则返回错误。 dst,scr都必须是一个存在的文件夹,否则返回错误。

func CopyFile

func CopyFile(src, dst string, overwrite bool) error

复制文件到指定目录

overwrite为true时,如果目标文件存在则覆盖, overwrite为false时,如果目标文件存在则返回错误。 dst必须是一个存在的文件夹,否则返回错误。 scr为文件的绝对或相对路径(包含文件名)。

func CopyFileOrDir

func CopyFileOrDir(src, dst string, overwrite bool) error

复制文件或文件夹

overwrite为true时,如果目标文件存在则覆盖(dst中的目标文件或文件夹会被直接删除), overwrite为false时,如果目标文件存在则返回错误。 scr,dst 为绝对或相对路径,dst必须是一个文件夹(可以不存在)。

func CreateShortcut

func CreateShortcut(filename, dir string) error

给目录或文件创建快捷方式(filename可以为绝对路径也可以为相对路径,dir必须是绝对路径)

func ExecutionFilePath

func ExecutionFilePath() (string, error)

获取当前程序源代码的详细路径 D:/Go/workspace/port/network_learn/server/server.go

func FileIsExist

func FileIsExist(path string) bool

文件是否存在

func FileOrDirIsExist

func FileOrDirIsExist(path string) bool

文件或文件夹是否存在

func GatMd5

func GatMd5(content []byte) ([]byte, error)

计算md5

func GatMd5Hex

func GatMd5Hex(content []byte) (string, error)

func GenRandomAsciiString added in v0.2.1

func GenRandomAsciiString(length int) string

GenRandomAsciiString 生成指定长度的随机字符串,只包含大小写字母和数字。

func GenRandomString added in v0.2.1

func GenRandomString(charset string, length int) string

func GetAllNamesInPath

func GetAllNamesInPath(path string) ([]string, error)

获取path路径下的文件(含后缀)和文件夹名称

func GetAllNamesRecursive

func GetAllNamesRecursive(path string) ([]string, error)

递归获取path下所有文件和文件夹 path决定返回的文件路径是绝对路径还是相对路径。

func GetCStringLen

func GetCStringLen(str unsafe.Pointer) int

func GetCurrentPath

func GetCurrentPath() (string, error)

获取当前程序的执行环境路径(不包含可执行文件名称)

func GetExecutionPath

func GetExecutionPath() (string, error)

获取当前程序所在的绝对路径+文件名

func GetExecutionPath2

func GetExecutionPath2() (string, error)

获取当前程序的执行路径(包含可执行文件名称) C:\Users\*\AppData\Local\Temp\*\exe\main.exe 或 .\main.exe (读取命令参数的方式)

func GetFileMd5

func GetFileMd5(filename string) ([]byte, error)

获取文件md5

func GetFileNamesRecursive

func GetFileNamesRecursive(path string) ([]string, error)

递归获取path下所有文件(包含子文件夹中的文件)。 path决定返回的文件路径是绝对路径还是相对路径。

func GetFileNmaesInPath

func GetFileNmaesInPath(path string) ([]string, error)

获取path下所有文件名称(含后缀,不含路径)

func GetFileSha1

func GetFileSha1(filename string) (string, error)

获取文件的SHA1值(字母小写)

func GetFolderNamesInPath

func GetFolderNamesInPath(path string) ([]string, error)

获取path路径下的文件夹名称(不含路径)

func GetFolderNamesRecursive

func GetFolderNamesRecursive(path string) ([]string, error)

递归获取path下所有文件夹(包含子文件夹) path决定返回的文件路径是绝对路径还是相对路径。

func GetFormatedTimeFromUnixMilli

func GetFormatedTimeFromUnixMilli(rawTime int64, format string) string

时间戳毫秒 -> format time(Local)。 if rawTime is "" , return current time。

func GetFormatedTimeFromUnixMilliStr

func GetFormatedTimeFromUnixMilliStr(rawTime string, format string) (string, error)

时间戳毫秒 -> format time(Local)。 if rawTime is "" , return current time。

func GetRandomUserAgent

func GetRandomUserAgent() string

随机获取user-agent(不含移动端)

func GetSha1

func GetSha1(data []byte) ([]byte, error)

GetSha1 获取[]byte的SHA1值(字母小写)

func GetSha256

func GetSha256(content []byte) ([]byte, error)

计算sha256

func GetYesterday

func GetYesterday() time.Time

获取昨天的日期

func HexToInt

func HexToInt(hex string) (int, error)

十六进制转换为十进制

func IsAdmin

func IsAdmin() bool

判断当前进程是否以管理员身份运行

func IsChildDir

func IsChildDir(parent, child string) bool

判断child是否是parent的子文件夹(不存在的文件夹会返回false)

func IsChildDir2

func IsChildDir2(parent, child string) bool

判断child是否是parent的子文件夹(为了性能只是简单的判断前缀,需要保证路径分隔符一致)

func IsDir

func IsDir(path string) (is bool, exist bool, err error)

是否为文件夹

func IsFile

func IsFile(path string) (is bool, exist bool, err error)

是否为文件

func MoveFileOrDir

func MoveFileOrDir(src, dst string, overwrite bool) error

移动文件或文件夹到指定目录

overwrite为true时,如果目标文件存在则覆盖(dst中的目标文件或文件夹会被直接删除), overwrite为false时,如果目标文件存在则返回错误。 dst必须是一个存在的文件夹,否则返回错误。 scr为的绝对或相对路径。

func PressEnterKeyToContinue

func PressEnterKeyToContinue()

func PressEnterKeyToContinue2

func PressEnterKeyToContinue2(ch chan bool)

func PressEnterKeyToContinueWithTimeout

func PressEnterKeyToContinueWithTimeout(timeout time.Duration)

Press Enter Key to Continue with Timeout,超时则退出程序

func ReadAll added in v0.2.0

func ReadAll(reader io.Reader, buf []byte) (n int, err error)

ReadAll reads from reader until buf is full or an error occurs. If buf is full before EOF, ReadAll returns an error.

func ReadLines

func ReadLines(reader io.Reader) (lines [][]byte, err error)

func ReadStartWithLastLine

func ReadStartWithLastLine(filename string, n int) (string, error)

读取倒数第n行(n从1开始), 若n大于文件行数则返回错误io.EOF。

func ReadTrimmedLines

func ReadTrimmedLines(reader io.Reader) (lines [][]byte, err error)

ReadTrimmedLines 从给定的 io.Reader 中读取内容,并按行分割成字节切片。 开头和结尾的空白行将被去除。 返回值 lines 是一个二维字节切片,每个元素代表一行的内容。

func ReverseRead

func ReverseRead(name string, lineNum uint) ([]string, error)

从文件末尾按行读取文件。 name:文件路径 lineNum:读取行数(超过文件行数则读取全文)。 最后一行为空也算读取了一行,会返回此行为空串,若全是空格也会原样返回。 返回的每一行都不包含换行符号。

func ScanFields

func ScanFields(
	lines []string,
	fieldSpaceLimit int,
	recordSpaceLimit int,
	fieldKeyWords map[string]func(string) bool,
) (fields []string, records [][]string, err error)

ScanFields 函数的作用是解析一组文本行(lines),将第一行作为字段名称(fields)提取, 并将剩余的行解析为记录(records),每条记录是字段值的集合。 这个函数可以处理有限数量的空格字符来分隔记录中的字段。 函数的参数: lines: 一个字符串切片,包含要解析的文本行。 recordSpaceLimit: 一个整数,指定字段之间的最小空格数来认为字段是分开的。 如果为0,则使用任意数量的空格来分隔字段。 需要保证第一行是字段名, 且后面每行都是有效的记录。

例如,下面的文本行: Name Access Availability BlockSize

C: 3 0 4096

D: 3 4096

E: 3 1 4096

F: 1 4096

将被解析为: fields = ["Name", "Access", "Availability", "BlockSize"]

records = [

["C:", "3", "0", "4096"],
["D:", "3", "", "4096"],
["E:", "3", "1", "4096"],
["F:", "", "1", "4096"],

]

func SplitBySpaceLimit

func SplitBySpaceLimit(line string, spaceLimit int) []string

func SplitBySpaceLimit2

func SplitBySpaceLimit2(line string, spaceLimit int) []string

func Str2int32

func Str2int32(str string) int32

Str2int32 将字符串转换为int32 使用前请确保传入的字符串是合法的

func Str2int64

func Str2int64(str string) int64

Str2int64 将字符串转换为int64 使用前请确保传入的字符串是合法的

func Str2uint64

func Str2uint64(str string) uint64

Str2uint64 将字符串转换为uint64 使用前请确保传入的字符串是合法的

func StrLen

func StrLen(str string) int

StrLen统计字符串长度

func StringAsPointer

func StringAsPointer(s string) (unsafe.Pointer, int)

func StringToBytes

func StringToBytes(s string) []byte

func UnCompress

func UnCompress(zipFile, dest string) error

解压

Types

type BufWriteFlushCloser

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

实现Close时自动Flush再Close

func NewBufWriteCloser

func NewBufWriteCloser(w io.WriteCloser) *BufWriteFlushCloser

func NewBufWriteCloserSize

func NewBufWriteCloserSize(w io.WriteCloser, size int) *BufWriteFlushCloser

func (*BufWriteFlushCloser) Close

func (b *BufWriteFlushCloser) Close() error

Close closes the BufWriteFlushCloser, flushing the buffer and closing the underlying writer.

func (*BufWriteFlushCloser) Flush

func (b *BufWriteFlushCloser) Flush() error

func (*BufWriteFlushCloser) Write

func (b *BufWriteFlushCloser) Write(p []byte) (n int, err error)

type CopyChecker added in v0.2.0

type CopyChecker uintptr

CopyChecker holds back pointer to itself to detect object copying.

func (*CopyChecker) Check added in v0.2.0

func (c *CopyChecker) Check() error

Check checks if the CopyChecker object has been copied. The Check method records its address the first time it is called and checks whether its address has changed the next time it is called. The Check method is thread-safe and can be called from multiple goroutines.

type NoCopy added in v0.2.0

type NoCopy struct{}

NoCopy may be added to structs which must not be copied after the first use.

See https://golang.org/issues/8005#issuecomment-190753527 for details.

Note that it must not be embedded, due to the Lock and Unlock methods.

func (*NoCopy) Lock added in v0.2.0

func (*NoCopy) Lock()

Lock is a no-op used by -copylocks checker from `go vet`.

Don't remove it, as `go vet` won't recognize the type as

func (*NoCopy) Unlock added in v0.2.0

func (*NoCopy) Unlock()

type Pair

type Pair[T1, T2 any] struct {
	First  T1
	Second T2
}

type Result

type Result[T any] struct {
	Err   error
	Value T
}

type SimpleKV

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

func NewSimpleKV

func NewSimpleKV(dbPath string) (*SimpleKV, error)

func (*SimpleKV) Delete

func (kv *SimpleKV) Delete(key string) error

func (*SimpleKV) Get

func (kv *SimpleKV) Get(key string) (string, bool)

func (*SimpleKV) Set

func (kv *SimpleKV) Set(key, value string) error

func (*SimpleKV) SetIfNotExist added in v0.2.1

func (kv *SimpleKV) SetIfNotExist(key, value string) (bool, error)

type StdBaseLogger

type StdBaseLogger interface {
	Errorf(string, ...interface{})
	Errorln(...interface{})
	Warnf(string, ...interface{})
	Warnln(...interface{})
	Infof(string, ...interface{})
	Infoln(...interface{})
	Debugf(string, ...interface{})
	Debugln(...interface{})
	Tracef(string, ...interface{})
	Traceln(...interface{})
}

type StdLogger

type StdLogger interface {
	StdBaseLogger
	Panicf(string, ...interface{})
	Panicln(...interface{})
}

type WriteFlushCloser

type WriteFlushCloser interface {
	io.WriteCloser
	Flush() error
}

Directories

Path Synopsis
usb
hid
HID package to access Human Interface Devices.
HID package to access Human Interface Devices.
usbdrivedetector
Package usbdrivedetector detects all USB storage devices connected to a computer.
Package usbdrivedetector detects all USB storage devices connected to a computer.

Jump to

Keyboard shortcuts

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