stream

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2025 License: Apache-2.0 Imports: 41 Imported by: 26

Documentation

Index

Constants

View Source
const TimeLayout = "2006-01-02 15:04:05"

Variables

View Source
var (
	RegexpIp     = regexp.MustCompile(`((25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))`)
	RegexpIpPort = regexp.MustCompile(`((25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d))):([0-9]+)`)
)
View Source
var DefaultFileServerPort = ":8080"
View Source
var RegexpCenter = `(.+?)`

Functions

func AlignString

func AlignString(s string, length int) (ss string)

func Atoi

func Atoi(s string) int

func BaseName

func BaseName(path string) string

func Bool2Integer

func Bool2Integer[T Integer](b bool) T

func CapitalizeWords

func CapitalizeWords(s string) string

CapitalizeWords capitalizes the first letter of each word in a string.

func ConvertUtf82Gbk

func ConvertUtf82Gbk(src string) string

func Copy

func Copy(src, dst string)

Copy src to dst. src may be a directory, file, or symlink.

func CopyDir

func CopyDir(dst, src string)

func CopyFile

func CopyFile(path, dstPath string)

func CopyWithMask

func CopyWithMask(src, dst string, mask fs.FileMode)

CopyWithMask src to dst. src may be a directory, file, or symlink.

func CreatDirectory

func CreatDirectory(dir string) bool

func CurrentDirName

func CurrentDirName(path string) (currentDirName string)

func DirDepth

func DirDepth(dirPath string) (depth int)

func DumpHex

func DumpHex[T []byte | *bytes.Buffer](buf T) (dump string)

func FileExists

func FileExists(path string) bool

FileExists returns true if the path points to a regular file.

func FileLineCountIsMoreThan

func FileLineCountIsMoreThan(path string, n int) bool

func FileServer

func FileServer()

func FileServerFS

func FileServerFS(fs embed.FS)

func FirstToLower

func FirstToLower(in string) string

FirstToLower converts the first character to lower case.

func FirstToUpper

func FirstToUpper(in string) string

FirstToUpper converts the first character to upper case.

func Float64Cut

func Float64Cut(value float64, bits int) (float64, error)

func Float64ToString

func Float64ToString(f float64, prec int) string

func FormatInteger

func FormatInteger[T Integer](data T) string

func FormatIntegerHex

func FormatIntegerHex[T Integer](data T) string

func FormatIntegerHex0x

func FormatIntegerHex0x[T Integer](data T) string

func FormatTime

func FormatTime(t time.Time) string

func GenA2Z

func GenA2Z() iter.Seq[string]

func GenMask

func GenMask()

func GetAvailablePort

func GetAvailablePort() int

GetAvailablePort 获取可用端口

func GetDaysDiff

func GetDaysDiff(dstTime string) string

func GetDesktopDir

func GetDesktopDir() string

func GetLastCommitHashLocal

func GetLastCommitHashLocal(repositoryDir string) string

func GetLocalIPs

func GetLocalIPs() []net.IP

func GetPackageName

func GetPackageName() (pkgName string)

func GetTimeNowString

func GetTimeNowString() string

func GetTimeStamp

func GetTimeStamp() string

func GetTimeStamp13Bits

func GetTimeStamp13Bits() int64

func GetUserConfigDirs

func GetUserConfigDirs() (UserConfigDirs map[string]string)

func GetWindowsLogicalDrives

func GetWindowsLogicalDrives() iter.Seq[string]

func GitProxy

func GitProxy(isSetProxy bool)

func GoReleaser

func GoReleaser()

func HomeDir

func HomeDir() string

func Integer2Bool

func Integer2Bool[T Integer](value T) bool

func IntegerToIP

func IntegerToIP(ip int64) string

func IsASCIIDigit

func IsASCIIDigit(s string) bool

func IsAndroid

func IsAndroid() bool

func IsDarwin

func IsDarwin() bool

func IsDir

func IsDir(path string) bool

IsDir returns true if the specified path exists and is a directory.

func IsDirEx

func IsDirEx(path string) (ok bool)

func IsDirRoot

func IsDirRoot(path string) bool

func IsFilePath

func IsFilePath(path string) bool

func IsFilePathEx

func IsFilePathEx(path string) (ok bool)

func IsFreebsd

func IsFreebsd() bool

func IsIncludeLine

func IsIncludeLine(s string) bool

func IsIos

func IsIos() bool

func IsJs

func IsJs() bool

func IsLinux

func IsLinux() bool

func IsPortAvailable

func IsPortAvailable(port int) bool

IsPortAvailable 判断端口是否可以(未被占用)

func IsTermux

func IsTermux() bool

func IsTruthy

func IsTruthy(in string) bool

IsTruthy returns true for "truthy" values, i.e. ones that should be interpreted as true.

func IsWindows

func IsWindows() bool

func IsZero

func IsZero(v reflect.Value) bool

func JoinHomeDir

func JoinHomeDir(path string) (join string)

func JoinHomeFile

func JoinHomeFile(path string) (join string)

func JsonIndent

func JsonIndent(b []byte) string

func Lines

func Lines(s string) iter.Seq2[int, string]

Lines returns an iterator over the newline-terminated lines in the string s. The lines yielded by the iterator include their terminating newlines. If s is empty, the iterator yields no lines at all. If s does not end in a newline, the final yielded line will not end in a newline. It returns a single-use iterator with both line number and line content.

func LinesBytes

func LinesBytes(s []byte) iter.Seq2[int, []byte]

LinesBytes returns an iterator over the newline-terminated lines in the byte slice s. The lines yielded by the iterator include their terminating newlines. If s is empty, the iterator yields no lines at all. If s does not end in a newline, the final yielded line will not end in a newline. It returns a single-use iterator.

func MarshalJSON

func MarshalJSON(v any) []byte

func MarshalJsonToFile

func MarshalJsonToFile(v any, name string)

func NaturalCmp

func NaturalCmp(s1, s2 string, caseInsensitive bool) int

NaturalCmp compares two strings using natural ordering. This means that "a2" < "a12".

Non-digit sequences and numbers are compared separately. The former are compared byte-wise, while the latter are compared numerically (except that the number of leading zeros is used as a tie-breaker, so "2" < "02").

Limitations:

  • only ASCII digits (0-9) are considered.

Original algorithm: https://github.com/fvbommel/util/blob/master/sortorder/natsort.go

func NaturalLess

func NaturalLess(s1, s2 string, caseInsensitive bool) bool

NaturalLess compares two strings using natural ordering. This means that "a2" < "a12".

Non-digit sequences and numbers are compared separately. The former are compared byte-wise, while the latter are compared numerically (except that the number of leading zeros is used as a tie-breaker, so "2" < "02").

Limitations:

  • only ASCII digits (0-9) are considered.

Original algorithm: https://github.com/fvbommel/util/blob/master/sortorder/natsort.go

func NewVersion

func NewVersion[T string | uint64](s ...T) (v *object)

func ParseFloat

func ParseFloat(sizeStr string) (size float64)

func ParseGoMod

func ParseGoMod(file string, data []byte) *safemap.M[string, string]

func ParseInt

func ParseInt(s string) int64

func ParseUint

func ParseUint(s string) uint64

func Permute

func Permute[T comparable](data []T) [][]T

Permute 递归回溯法实现全排列 https://www.cnblogs.com/xwxz/p/14812448.html

func PermuteToUint32Slice

func PermuteToUint32Slice(slice [][]byte) []uint32

func RandomAnySlice

func RandomAnySlice[T any](slice []T) T

func ReadEmbedFileMap

func ReadEmbedFileMap(embedFiles embed.FS, dir string) *safemap.M[string, []byte]

func ReadFileToChunks

func ReadFileToChunks(path string, n int) iter.Seq[[]byte]

func ReadFileToLines

func ReadFileToLines(path string) iter.Seq[string]

func ReflectVisibleFields

func ReflectVisibleFields(object any) iter.Seq2[int, reflect.StructField]

func RegexpWebBodyBlocks

func RegexpWebBodyBlocks(tagName string) string

func RunDir

func RunDir() string

func Slice

func Slice(s any) []byte

Slice returns a byte slice view of a slice.

func SortStringsNaturalAscending

func SortStringsNaturalAscending(in []string)

SortStringsNaturalAscending sorts a slice of strings using NaturalLess in least to most order.

func SortStringsNaturalDescending

func SortStringsNaturalDescending(in []string)

SortStringsNaturalDescending sorts a slice of strings using NaturalLess in most to least order.

func StripBOM

func StripBOM(b []byte) []byte

StripBOM removes the BOM marker from UTF-8 data, if present.

func Struct

func Struct(s any) []byte

Struct returns a byte slice view of a struct.

func ToCamel

func ToCamel(data string) string

func ToCamelToLower

func ToCamelToLower(s string) string

func ToCamelUpper

func ToCamelUpper(s string) string

func TopologicalSort

func TopologicalSort[T comparable](m *safemap.M[T, []T], allowCyclicDependency bool) (sorted []T)

func TrimExtension

func TrimExtension(path string) string

func TrimSlash

func TrimSlash(name string) string

func Uint32

func Uint32(s []uint32) []byte

Uint32 returns a byte slice view of a uint32 slice.

func Unquote

func Unquote(line string) string

func UnquoteBytes

func UnquoteBytes(text []byte) []byte

UnquoteBytes strips up to one set of surrounding double quotes from the bytes and returns them as a string. For a more capable version that supports different quoting types and unescaping, consider using strconv.Unquote().

func Unquote_

func Unquote_(text string) string

Unquote strips up to one set of surrounding double quotes from the bytes and returns them as a string. For a more capable version that supports different quoting types and unescaping, consider using strconv.Unquote().

func UpdateAllLocalRep

func UpdateAllLocalRep()

func UpdateWorkSpace

func UpdateWorkSpace(isUpdateAll bool)

func ValueIsBytesType

func ValueIsBytesType(v reflect.Value) bool

func Wrap

func Wrap(prefix, text string, maxColumns int) string

Wrap text to a certain length, giving it an optional prefix on each line. Words will not be broken, even if they exceed the maximum column size and instead will extend past the desired length.

func WriteAppend

func WriteAppend[T Type](name string, data T)

func WriteBinaryFile

func WriteBinaryFile[T Type](name string, data T)

func WriteGoFile

func WriteGoFile[T Type](name string, data T)

func WriteTruncate

func WriteTruncate[T Type](name string, data T)

Types

type Buffer

type Buffer struct {
	*bytes.Buffer
	// contains filtered or unexported fields
}

全排列 矩阵置换 拓扑排序 N叉树 treeGrid

func NewBuffer

func NewBuffer[T Type](data T) *Buffer

func NewHexDump

func NewHexDump(hexdumpStr HexDumpString) (data *Buffer)

func NewHexString

func NewHexString(s HexString) *Buffer

func ReaderGzip

func ReaderGzip[T Type](data T) *Buffer

func SwapAdjacent

func SwapAdjacent[T Type](data T) *Buffer

func (*Buffer) Append

func (b *Buffer) Append(others ...*Buffer) *Buffer

func (*Buffer) AppendByteSlice

func (b *Buffer) AppendByteSlice(bytesSlice ...[]byte) []byte

func (*Buffer) BigNumXorWithAlign

func (b *Buffer) BigNumXorWithAlign(arg1, arg2 []byte, align int) []byte

func (*Buffer) Contains

func (b *Buffer) Contains(substr string) bool

func (*Buffer) CutWithIndex

func (b *Buffer) CutWithIndex(x, y int) []byte

func (*Buffer) Empty

func (b *Buffer) Empty() bool

func (*Buffer) HexString

func (b *Buffer) HexString() HexString

func (*Buffer) HexStringUpper

func (b *Buffer) HexStringUpper() HexString

func (*Buffer) Indent

func (b *Buffer) Indent(deep int)

func (*Buffer) InsertByte

func (b *Buffer) InsertByte(index int, ch byte)

func (*Buffer) InsertBytes

func (b *Buffer) InsertBytes(index int, insert []byte)

func (*Buffer) InsertString

func (b *Buffer) InsertString(index int, s string) *Buffer

func (*Buffer) Join

func (b *Buffer) Join(sep string, size int) string

func (*Buffer) NewLine

func (b *Buffer) NewLine() *Buffer

func (*Buffer) ObjectBegin

func (b *Buffer) ObjectBegin()

func (*Buffer) ObjectEnd

func (b *Buffer) ObjectEnd()

func (*Buffer) Peek

func (b *Buffer) Peek(n int) []byte

func (*Buffer) Quote

func (b *Buffer) Quote()

func (*Buffer) QuoteWith

func (b *Buffer) QuoteWith(s string) *Buffer

func (*Buffer) ReWriteSelf

func (b *Buffer) ReWriteSelf()

func (*Buffer) ReWriteSelfGo

func (b *Buffer) ReWriteSelfGo()

func (*Buffer) ReadBinary

func (b *Buffer) ReadBinary(order binary.ByteOrder) (data any)

func (*Buffer) ReadN

func (b *Buffer) ReadN(n int) []byte

func (*Buffer) ReaderGzip

func (b *Buffer) ReaderGzip() *Buffer

func (*Buffer) Replace

func (b *Buffer) Replace(old, new string, n int) *Buffer

func (*Buffer) ReplaceAll

func (b *Buffer) ReplaceAll(old, new string) *Buffer

func (*Buffer) Reverse

func (b *Buffer) Reverse() *Buffer

func (*Buffer) SliceBegin

func (b *Buffer) SliceBegin()

func (*Buffer) SliceEnd

func (b *Buffer) SliceEnd()

func (*Buffer) ToLines

func (b *Buffer) ToLines() (lines iter.Seq[string])

func (*Buffer) TrimPrefix

func (b *Buffer) TrimPrefix(prefix string) *Buffer

func (*Buffer) TrimSpace

func (b *Buffer) TrimSpace() *Buffer

func (*Buffer) TrimSuffix

func (b *Buffer) TrimSuffix(suffix string) *Buffer

func (*Buffer) WriteBinary

func (b *Buffer) WriteBinary(order binary.ByteOrder, data any)

func (*Buffer) WriteBytesLn

func (b *Buffer) WriteBytesLn(buf []byte) *Buffer

func (*Buffer) WritePackageName

func (b *Buffer) WritePackageName()

func (*Buffer) WriteStringLn

func (b *Buffer) WriteStringLn(s string) *Buffer

type Complex

type Complex interface {
	~complex64 | ~complex128
}

type Float

type Float interface {
	~float32 | ~float64
}

type GeneratedFile

type GeneratedFile struct {
	*Buffer
	// contains filtered or unexported fields
}

func NewGeneratedFile

func NewGeneratedFile() (g *GeneratedFile)

func RunCommand

func RunCommand(arg ...string) (stdOut *GeneratedFile)

func RunCommandSafe added in v0.1.4

func RunCommandSafe(arg ...string) (stdOut *GeneratedFile)

func RunCommandWithDir

func RunCommandWithDir(dir string, arg ...string) (stdOut *GeneratedFile)

func (*GeneratedFile) AddImport

func (g *GeneratedFile) AddImport(pkg string)

func (*GeneratedFile) EnumTypes

func (g *GeneratedFile) EnumTypes(name string, TypeTooltipMap *safemap.M[string, string])

func (*GeneratedFile) Format

func (g *GeneratedFile) Format() string

func (*GeneratedFile) InsertPackageWithImports

func (g *GeneratedFile) InsertPackageWithImports(packageName string) *GeneratedFile

func (*GeneratedFile) P

func (g *GeneratedFile) P(v ...any)

func (*GeneratedFile) PC

func (g *GeneratedFile) PC(is64Bit bool, v string)

func (*GeneratedFile) PKeepSpace

func (g *GeneratedFile) PKeepSpace(v ...any)

func (*GeneratedFile) ReadTemplates

func (g *GeneratedFile) ReadTemplates(path, pkg string)

func (*GeneratedFile) SetCallBack

func (g *GeneratedFile) SetCallBack(callBack func(is bool, v string) string)

func (*GeneratedFile) SetEnumBase

func (g *GeneratedFile) SetEnumBase(base int) *GeneratedFile

func (*GeneratedFile) SetEnumType

func (g *GeneratedFile) SetEnumType(t reflect.Type) *GeneratedFile

func (*GeneratedFile) SetFilePath

func (g *GeneratedFile) SetFilePath(filePath string) *GeneratedFile

func (*GeneratedFile) SetKeepOrigName

func (g *GeneratedFile) SetKeepOrigName(keepOrigName bool) *GeneratedFile

func (*GeneratedFile) SetValues

func (g *GeneratedFile) SetValues(values []uint32) *GeneratedFile

type HexDumpString

type HexDumpString string

type HexString

type HexString string

type Integer

type Integer interface {
	Signed | Unsigned
}

type Ordered

type Ordered interface {
	Integer | Float | ~string
}

type Pool

type Pool[T any] struct {
	// contains filtered or unexported fields
}

func NewPool

func NewPool[T any](fn func() T) *Pool[T]

func (*Pool[T]) Get

func (p *Pool[T]) Get() T

func (*Pool[T]) Put

func (p *Pool[T]) Put(v T)

type Signed

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Type

type Type interface {
	string | HexString | HexDumpString | ~[]byte | cmp.Ordered | ~*bytes.Buffer | *big.Int | *Buffer
}

全排列 矩阵置换 拓扑排序 N叉树 treeGrid

type Unsigned

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

Directories

Path Synopsis
x command
Package desktop provides desktop integration utilities.
Package desktop provides desktop integration utilities.
net

Jump to

Keyboard shortcuts

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