Documentation
¶
Overview ¶
* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-06-11 15:09:15 * @FilePath: \go-toolbox\pkg\osx\base.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2024-10-28 09:52:21 * @LastEditors: kamalyes 501893067@qq.com * @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 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @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 501893067@qq.com * @Date: 2024-11-09 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @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 GetClientPublicIP(r *http.Request) (string, error)
- func GetConNetPublicIp(urls ...string) (string, error)
- func GetDirFiles(dir string) ([]string, error)
- func GetHostName() (string, error)
- func GetLocalInterfaceIeIp() (string, string, error)
- func GetLocalInterfaceIps() ([]net.IP, error)
- 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 GetClientPublicIP ¶ added in v0.11.5
GetClientPublicIP 从HTTP请求中获取客户端的公网IP地址。 如果无法确定公网IP,则返回空字符串和错误(如果适用)。
func GetConNetPublicIp ¶ added in v0.11.5
GetConNetPublicIp 联网获取本机公网 IP
func GetDirFiles ¶
GetDirFiles 获取指定目录及其子目录下的所有文件路径 参数:dir - 目录路径 返回:所有文件的路径切片和可能的错误
func GetLocalInterfaceIeIp ¶ added in v0.11.5
GetLocalInterfaceIeIp 返回本地网卡对应的外部和内部 IP 地址
func GetLocalInterfaceIps ¶ added in v0.11.5
GetLocalInterfaceIps 查询本机网卡所有IP
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 返回调用栈的格式化字符串,包含函数名、文件名和行号