Help us shape the future of Go! Take the 2026 Go Developer Survey

platform

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppDir

func AppDir() (string, error)

AppDir 返回当前可执行文件所在的目录。

func BundledModelsDir

func BundledModelsDir(appDir string) string

BundledModelsDir 返回打包自带的模型目录路径(绝对路径)。

func DataDir

func DataDir() string

DataDir 返回应用数据目录(绝对路径)。

Windows: exe 目录可写时返回 exe 目录(portable 模式,旧用户零迁移); 不可写(如装到 Program Files)时 fallback 到 %LOCALAPPDATA%\Goink。 其他平台: 返回 ~/Goink/。 开发模式下 exe 位于临时目录时,所有平台统一返回 ~/Goink/。 环境变量 GOINK_DATA_DIR 可覆盖以上逻辑,用于集成测试。

结果用 sync.Once 缓存,避免每次调用都做可写性检测。 测试二进制下不做缓存:测试用 t.Setenv 切换 GOINK_DATA_DIR,而 t.Setenv 只在测试 结束时恢复环境变量、不会恢复这里的缓存,缓存会让后一个测试拿到前一个测试已删除 的临时目录。

func ResetDataDirCache added in v1.4.3

func ResetDataDirCache()

ResetDataDirCache 重置 DataDir 的 sync.Once 缓存,供测试使用。 测试用例用 t.Setenv("GOINK_DATA_DIR", ...) 设置不同的临时目录后, 需要调用此函数重置缓存,否则 DataDir() 仍返回第一次调用的缓存值。 生产代码不应调用此函数。

func ResolveGit

func ResolveGit() (string, error)

ResolveGit 返回 git 可执行文件的路径。 搜索顺序: app 自带 runtime/git/ → 用户数据目录 runtime/git/ → 系统 PATH。 每个候选路径都会验证可执行性(git --version),不可用则跳过继续 fallback。

当环境变量 GOINK_E2E_STRICT=1 时,仅从 DataDir 的 bundled 路径查找, 不 fallback 到系统 PATH,找不到直接报错。E2E 专属,确保测试使用 bundled git。

当环境变量 GOINK_GIT_BIN 非空时,优先返回它指定的路径(需通过 git --version 验证), 优先级高于以上所有查找顺序。与 GOINK_DATA_DIR 同级:供测试显式注入 git 路径。

func ResolveOnnxLib

func ResolveOnnxLib() (string, error)

ResolveOnnxLib 返回 ONNX Runtime 动态库的路径。 优先 app 自带的 runtime/,然后用户数据目录 runtime/,最后系统路径。

当环境变量 GOINK_E2E_STRICT=1 时,仅从 DataDir 的 runtime/ 查找, 不 fallback 到系统路径,找不到直接报错。E2E 专属,确保测试使用 bundled ONNX。

func SetPlatformAttr

func SetPlatformAttr(*exec.Cmd)

SetPlatformAttr 为子进程设置平台相关属性(非 Windows 平台为空操作)。

Types

This section is empty.

Jump to

Keyboard shortcuts

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