tool

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IsWindows = runtime.GOOS == "windows"
	IsLinux   = runtime.GOOS == "linux"
	IsDarwin  = runtime.GOOS == "darwin"
)

Variables

This section is empty.

Functions

func BoolToString

func BoolToString(value any) string

BoolToString 布尔转字符串

func CheckSizeZero

func CheckSizeZero(size types.TSize) bool

func ContainsStrings

func ContainsStrings(strs []string, str string) bool

func CopyFile

func CopyFile(srcFilePath, dstFilePath string) error

func Decode

func Decode(r io.Reader) (image.Image, error)

func DecodeAll

func DecodeAll(r io.Reader) ([]image.Image, error)

func DecodeConfig

func DecodeConfig(r io.Reader) (image.Config, error)

func DetectImageFormatByte

func DetectImageFormatByte(imageData []byte) (string, error)

DetectImageFormatByte 检测图片真实格式

func Encode

func Encode(w io.Writer, im image.Image) error

Encode 将图像编码并写入到指定的io.Writer中

w: 用于写入编码后数据的io.Writer
im: 需要编码的图像
error: 编码过程中可能出现的错误

func Equal

func Equal(s1 string, s2 ...string) bool

判断字符串相等, 忽略大小写

func ExtractFile

func ExtractFile(zipFile *zip.File, outputPath, outputFilename string) (string, error)

ExtractFile 从zip文件中提取指定文件到目标路径

zipFile: 要提取的zip文件对象
targetFile: 目标文件路径
error: 提取过程中发生的错误,如果成功则返回nil

func ExtractOtherBuildArgs

func ExtractOtherBuildArgs(buildArgs string) []string

ExtractOtherBuildArgs 从构建参数字符串中提取其他构建参数 该函数会移除 -tags 和 -ldflags 相关的参数,并清理格式

buildArgs: 原始的构建参数字符串,可能包含各种 go build 选项
string: 清理后的构建参数字符串,移除了 -tags 和 -ldflags 参数,
        所有单引号已转换为双引号,多余空格已被清理

func FirstToUpper

func FirstToUpper(s string) string

第一个字母转为大写

func FixPropInfo

func FixPropInfo(methods *ArrayMap[string, *TMethod], prop *lcl.ComponentProperties)

FixPropInfo 修复属性信息,将属性名与对象方法名进行匹配和修正 @param methods 对象方法列表,用于查找和匹配属性对应的方法 @param prop 组件属性信息,需要被修正的属性对象

func FloatToString

func FloatToString(value any) string

FloatToString 浮点转字符串

func ImageListAddPng

func ImageListAddPng(imageList lcl.IImageList, filePath string)

加载图像到列表

func IntToString

func IntToString(value any) string

IntToString 数字转字符串

func IsDir

func IsDir(path string) bool

判断文件是否目录

func IsExist

func IsExist(path string) bool

判断文件是否存在

func IsMainThread

func IsMainThread() bool

判断当前是否为主线程

func LoadImageList

func LoadImageList(owner lcl.IComponent, imageList []string, width, height int32) lcl.IImageList

加载图片列表

func MergeLdflags

func MergeLdflags(defaultLdflags, customLdflags string) (mergedLdFlags []string)

MergeLdflags 合并默认和自定义的链接器标志(ldflags) 该函数将两个 ldflags 字符串按空格分割后合并,自动去除重复项 并保持原有的插入顺序

defaultLdflags: 默认的链接器标志字符串,多个标志间以空格分隔
customLdflags: 自定义的链接器标志字符串,多个标志间以空格分隔

mergedLdFlags: 合并后的链接器标志字符串切片,已去重且保持原有顺序,
               优先保留 defaultLdflags 中的标志,然后追加 customLdflags 中独有的标志

func MergeTags

func MergeTags(defaultTags, customTags string) (mergedTags []string)

MergeTags 合并默认和自定义的构建标签(tags) 该函数将两个 tags 字符串按逗号或空格分割后合并,自动去除重复项 并保持原有的插入顺序

defaultTags: 默认的构建标签字符串,多个标签间以逗号或空格分隔
customTags: 自定义的构建标签字符串,多个标签间以逗号或空格分隔

mergedTags: 合并后的构建标签字符串切片,已去重且保持原有顺序,
            优先保留 defaultTags 中的标签,然后追加 customTags 中独有的标签

func RemoveT

func RemoveT(name string) string

删除道字母 T

func RenderTemplate

func RenderTemplate(templateText string, data any) ([]byte, error)

func Replace

func Replace(s, old, new string) string

字符串替换

func Scale

func Scale(data []byte, targetW, targetH int) []byte

Scale 将PNG格式的图片数据缩放到指定尺寸

data: 原始PNG图片的字节数据
targetW: 目标宽度
targetH: 目标高度
[]byte: 缩放后的PNG图片字节数据,如果处理失败则返回nil

func SetToString

func SetToString(value any) string

SetToString 集合转字符串 [Xxx,Xxx,Xxx] > Xxx,Xxx,Xxx

func Split

func Split(s, sep string) []string

分割字符串并去除空字符串 aa,bb,,cc > [aa,bb,cc]

func StrToBool

func StrToBool(s string) (bool, error)

StrToBool 字符串转 bool "true"/"false"

func StrToFloat32

func StrToFloat32(s string) (float32, error)

StrToFloat32 字符串转 float32(范围:±3.4e38,精度约 6-7 位小数)

func StrToFloat64

func StrToFloat64(s string) (float64, error)

StrToFloat64 字符串转 float64(范围:±1.8e308,精度约 15-17 位小数)

func StrToInt

func StrToInt(s string) (int, error)

StrToInt 字符串转 int

func StrToInt8

func StrToInt8(s string) (int8, error)

StrToInt8 字符串转 int8(范围:-128 ~ 127)

func StrToInt16

func StrToInt16(s string) (int16, error)

StrToInt16 字符串转 int16(范围:-32768 ~ 32767)

func StrToInt32

func StrToInt32(s string) (int32, error)

StrToInt32 字符串转 int32(范围:-2147483648 ~ 2147483647)

func StrToInt64

func StrToInt64(s string) (int64, error)

StrToInt64 字符串转 int64(范围:-9223372036854775808 ~ 9223372036854775807)

func StrToUint

func StrToUint(s string) (uint, error)

StrToUint 字符串转 uint

func StrToUint8

func StrToUint8(s string) (uint8, error)

StrToUint8 字符串转 uint8(范围:0 ~ 255)

func StrToUint16

func StrToUint16(s string) (uint16, error)

StrToUint16 字符串转 uint16(范围:0 ~ 65535)

func StrToUint32

func StrToUint32(s string) (uint32, error)

StrToUint32 字符串转 uint32(范围:0 ~ 4294967295)

func StrToUint64

func StrToUint64(s string) (uint64, error)

StrToUint64 字符串转 uint64(范围:0 ~ 18446744073709551615)

func StrToUintptr

func StrToUintptr(s string) (uintptr, error)

StrToUintptr 字符串转 uintptr

func StringArrayReverse

func StringArrayReverse(array []string)

字符串数组元素反转

func ValueToTargetType

func ValueToTargetType(value any, targetType reflect.Type) (any, error)

ValueToTargetType 基本类型转换函数, 将值转换为目标类型

func ZipFolder

func ZipFolder(srcDir string, destZip string, skip *HashSet[string]) error

ZipFolder 将指定的文件夹打包成一个 ZIP 文件。 参数:

  • srcDir: 需要压缩的源文件夹路径,支持相对路径或绝对路径。
  • destZip: 输出的 ZIP 文件路径。
  • skip: 可选的 HashSet,用于指定需要跳过的顶层目录或文件名。如果为 nil,则不跳过任何内容。

返回值:

  • error: 如果在执行过程中发生错误则返回相应的错误信息,否则返回 nil。

Types

type Array

type Array[T comparable] struct {
	// contains filtered or unexported fields
}

func NewArray

func NewArray[T comparable]() *Array[T]

func (*Array[T]) Add

func (m *Array[T]) Add(value T)

func (*Array[T]) Adds

func (m *Array[T]) Adds(value ...T)

func (*Array[T]) Get

func (m *Array[T]) Get(index int) (T, bool)

func (*Array[T]) Len

func (m *Array[T]) Len() int

func (*Array[T]) Values

func (m *Array[T]) Values() []T

type ArrayMap

type ArrayMap[K, T comparable] struct {
	// contains filtered or unexported fields
}

func GetObjectMethodNames

func GetObjectMethodNames(v any) *ArrayMap[string, *TMethod]

GetObjectMethodNames 获取指定对象的所有方法名称 该函数通过反射机制遍历对象类型及其嵌套类型的所有方法,并返回一个包含所有方法名称的ArrayMap 参数:

v: 任意类型的对象实例,用于获取其方法信息

返回值:

*ArrayMap[string]: 包含所有方法名称的ArrayMap指针,如果输入为nil或无法获取类型信息则返回nil

func NewArrayMap

func NewArrayMap[K, T comparable]() *ArrayMap[K, T]

func (*ArrayMap[K, T]) Add

func (m *ArrayMap[K, T]) Add(key K, value T)

func (*ArrayMap[K, T]) ContainsKey

func (m *ArrayMap[K, T]) ContainsKey(key K) bool

func (*ArrayMap[K, T]) ContainsValue

func (m *ArrayMap[K, T]) ContainsValue(value T) bool

func (*ArrayMap[K, T]) Del

func (m *ArrayMap[K, T]) Del(key K)

func (*ArrayMap[K, T]) Get

func (m *ArrayMap[K, T]) Get(key K) T

func (*ArrayMap[K, T]) Iterate

func (m *ArrayMap[K, T]) Iterate(fn func(key K, value T) bool)

func (*ArrayMap[K, T]) Keys

func (m *ArrayMap[K, T]) Keys() []K

func (*ArrayMap[K, T]) Values

func (m *ArrayMap[K, T]) Values() (result []T)

type ArraySet

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

func NewArraySet

func NewArraySet() *ArraySet

func (*ArraySet) Add

func (m *ArraySet) Add(key string)

func (*ArraySet) Adds

func (m *ArraySet) Adds(keys ...string)

func (*ArraySet) ContainsKey

func (m *ArraySet) ContainsKey(key string) bool

func (*ArraySet) Iterate

func (m *ArraySet) Iterate(fn func(key string) bool)

func (*ArraySet) Sort

func (m *ArraySet) Sort()

func (*ArraySet) Values

func (m *ArraySet) Values() (result []string)

type Buffer

type Buffer struct {
	bytes.Buffer
}

func (*Buffer) WriteString

func (m *Buffer) WriteString(s ...string) *Buffer

type HashMap

type HashMap[K, T comparable] struct {
	// contains filtered or unexported fields
}

func NewHashMap

func NewHashMap[K, T comparable]() *HashMap[K, T]

func (*HashMap[K, T]) Add

func (m *HashMap[K, T]) Add(key K, value T)

func (*HashMap[K, T]) Clear

func (m *HashMap[K, T]) Clear()

func (*HashMap[K, T]) ContainsKey

func (m *HashMap[K, T]) ContainsKey(key K) bool

func (*HashMap[K, T]) ContainsValue

func (m *HashMap[K, T]) ContainsValue(value T) (key K, ok bool)

func (*HashMap[K, T]) Get

func (m *HashMap[K, T]) Get(key K) T

func (*HashMap[K, T]) Iterate

func (m *HashMap[K, T]) Iterate(fn func(key K, value T) bool)

func (*HashMap[K, T]) Remove

func (m *HashMap[K, T]) Remove(name K)

func (*HashMap[K, T]) Values

func (m *HashMap[K, T]) Values() map[K]T

type HashSet

type HashSet[T comparable] struct {
	// contains filtered or unexported fields
}

func NewHashSet

func NewHashSet[T comparable]() *HashSet[T]

func NewHashSetByValues

func NewHashSetByValues[T comparable](values ...T) *HashSet[T]

func SetToHashSet

func SetToHashSet(value any) *HashSet[string]

SetToHashSet 该函数将Set类型转换为HashSet

func (*HashSet[T]) Add

func (m *HashSet[T]) Add(value ...T)

func (*HashSet[T]) Contains

func (m *HashSet[T]) Contains(key T) bool

func (*HashSet[T]) Iterate

func (m *HashSet[T]) Iterate(fn func(key T) bool)

func (*HashSet[T]) Values

func (m *HashSet[T]) Values() (values []T)

type ImageList

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

func NewImageList

func NewImageList(owner lcl.IComponent, dirName string, rect ImageRect) *ImageList

func (*ImageList) ImageIndex

func (m *ImageList) ImageIndex(name string) int32

func (*ImageList) ImageList100

func (m *ImageList) ImageList100() lcl.IImageList

func (*ImageList) ImageList150

func (m *ImageList) ImageList150() lcl.IImageList

func (*ImageList) ImageList200

func (m *ImageList) ImageList200() lcl.IImageList

type ImageRect

type ImageRect struct {
	Image100 types.TSize
	Image150 types.TSize
	Image200 types.TSize
}

type Null

type Null struct{}

Null 空结构体

type TMethod

type TMethod struct {
	Name       string // 方法名
	StructName string // 所属结构
	Level      int    // 等级, 0~[1...] 数字越小表示优先级高
}

TMethod 存储方法信息

Jump to

Keyboard shortcuts

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