Documentation
¶
Overview ¶
* @Author: kamalyes [email protected] * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes [email protected] * @LastEditTime: 2025-12-04 19:31:22 * @FilePath: \go-toolbox\pkg\osx\base.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes [email protected] * @Date: 2025-09-21 03:50:15 * @LastEditors: kamalyes [email protected] * @LastEditTime: 2025-09-21 03:55:26 * @FilePath: \go-toolbox\pkg\osx\env.go * @Description: * * Copyright (c) 2025 by kamalyes, All Rights Reserved.
* @Author: kamalyes [email protected] * @Date: 2024-10-28 09:52:21 * @LastEditors: kamalyes [email protected] * @LastEditTime: 2024-11-11 10:53:21 * @FilePath: \go-toolbox\pkg\osx\file.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes [email protected] * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes [email protected] * @LastEditTime: 2024-11-26 13:32:51 * @FilePath: \go-toolbox\pkg\osx\goos.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes [email protected] * @Date: 2024-11-09 00:50:58 * @LastEditors: kamalyes [email protected] * @LastEditTime: 2024-11-11 17:08:09 * @FilePath: \go-toolbox\pkg\osx\path.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
Index ¶
- Constants
- Variables
- func CheckImageExists(filename string) error
- func Command(bin string, argv []string, baseDir string) ([]byte, error)
- func ComputeHashes(filePath string) (map[sign.HashCryptoFunc]string, error)
- func Copy(src, dest string) error
- func CreateIfNotExist(file string) (*os.File, error)
- func DirHasContent(dir string) (bool, []string, error)
- func FileExists(file string) bool
- func FileNameWithoutExt(file string) string
- func GetDatacenterId() int64
- func GetDirFiles(dir string) ([]string, error)
- func GetHostName() (string, error)
- func GetWorkerId() int64
- func GetWorkerIdForSnowflake() int64
- func Getenv[T any](key string, defaultValue T) T
- func HashUnixMicroCipherText() string
- func IsLinux() bool
- func IsMac() bool
- func IsSupportedOS() bool
- func IsWindows() bool
- func JoinPaths(absolutePath, relativePath string) string
- func JoinURL(base, p string) (string, error)
- func MkdirIfNotExist(dir string) error
- func MkdirTemp() string
- func ParseUrlPath(urlString string) (path string)
- func RemoveIfExist(filename string) error
- func SafeGetHostName() string
- func SaveImage(filename string, imgData []byte, quality int) error
- func StableHashSlot(s string, minNum, maxNum int) int
- func WriteContentToFile(filePath, content string) error
- type RunTimeCaller
Constants ¶
const ( OSMac = "darwin" OSWindows = "windows" OSLinux = "linux" )
定义操作系统常量
Variables ¶
var GetGOOS = func() string { return runtime.GOOS }
GetGOOS 返回当前操作系统
Functions ¶
func CheckImageExists ¶
CheckImageExists 检查图像文件是否存在并且有效
func ComputeHashes ¶ added in v0.11.6
func ComputeHashes(filePath string) (map[sign.HashCryptoFunc]string, error)
ComputeHashes 计算文件的多种哈希值,优化为只读一次文件
func CreateIfNotExist ¶ added in v0.11.6
CreateIfNotExist 如果文件不存在则创建它
func DirHasContent ¶ added in v0.11.6
DirHasContent 检查目录是否有内容(即是否有非空文件)
func FileNameWithoutExt ¶ added in v0.11.6
FileNameWithoutExt 返回不带扩展名的文件名
func GetDatacenterId ¶ added in v0.11.84
func GetDatacenterId() int64
GetDatacenterId 获取数据中心ID (新增) 优先级: 环境变量 DATACENTER_ID > 区域环境变量 > 默认值1 返回范围: 0-31 (雪花算法标准)
func GetDirFiles ¶
GetDirFiles 获取指定目录及其子目录下的所有文件路径 参数:dir - 目录路径 返回:所有文件的路径切片和可能的错误
func GetWorkerId ¶ added in v0.11.62
func GetWorkerId() int64
GetWorkerId 获取唯一的 Worker ID (智能增强版) 优先级: 环境变量 WORKER_ID > 主机名哈希 支持环境变量: WORKER_ID, NODE_ID, POD_ORDINAL 返回范围: 0-1023
func GetWorkerIdForSnowflake ¶ added in v0.11.84
func GetWorkerIdForSnowflake() int64
GetWorkerIdForSnowflake 专门为雪花算法获取WorkerId (新增) 返回范围: 0-31 (雪花算法标准的5位worker id)
func IsSupportedOS ¶ added in v0.11.15
func IsSupportedOS() bool
IsSupportedOS 检查当前操作系统是否在支持的操作系统列表中
func MkdirIfNotExist ¶ added in v0.11.6
MkdirIfNotExist 如果目录不存在则创建它
func ParseUrlPath ¶ added in v0.11.55
ParseUrlPath 解析Url中Path部分
func RemoveIfExist ¶ added in v0.11.6
RemoveIfExist 如果文件存在则删除它
func StableHashSlot ¶ added in v0.11.54
StableHashSlot 根据输入字符串 s 和范围 [minNum, maxNum],返回一个稳定且范围内的整数 使用加密哈希 sha256,抗碰撞更强 如果 maxNum < minNum,会 panic 如果 maxNum == minNum,直接返回 minNum
func WriteContentToFile ¶ added in v0.11.41
WriteContentToFile 将内容追加写入指定文件
Types ¶
type RunTimeCaller ¶ added in v0.11.6
type RunTimeCaller struct {
Pc uintptr // 程序计数器
File string // 文件名
Line int // 行号
FuncName string // 函数名
}
RunTimeCaller 结构体用于存储调用栈信息
func GetRuntimeCaller ¶ added in v0.11.34
func GetRuntimeCaller(skip int) *RunTimeCaller
GetRuntimeCaller 获取调用栈信息,调用者使用完需调用 Release() 归还对象
func (*RunTimeCaller) Release ¶ added in v0.11.48
func (c *RunTimeCaller) Release()
Release 放回对象池,调用者必须调用
func (*RunTimeCaller) String ¶ added in v0.11.57
func (c *RunTimeCaller) String() string
String 返回调用栈的格式化字符串,包含函数名、文件名和行号