Documentation
¶
Overview ¶
Package update 实现 openpe 的新版本检查与升级支撑(业务契约 docs/requirements/2026-08-25-version-and-update.md 方案 U):
- 通过 Go module proxy 的 /@latest 端点查询最新发布版本(尊重用户 GOPROXY——国内镜像用户自动走自己的镜像,无 GitHub API 配额问题);
- 把检查结果写入本地缓存文件并限频,hook 披露行只读缓存判断是否提醒, 增强关键路径永不发起网络请求;
- 版本比较基于 semver,永不建议降级;无法判定(devel)时抑制提醒。
Index ¶
- Constants
- func IsNewer(latest string, current string) bool
- func NoticeVersion(state CheckState, ok bool, current string, now time.Time, ...) (string, bool)
- func ResolveProxyBaseURL() string
- func SaveState(path string, state CheckState) error
- func StatePath(override string) (string, error)
- type CheckState
- type Client
- type LatestInfo
Constants ¶
const DefaultProxyBaseURL = "https://proxy.golang.org"
DefaultProxyBaseURL 是 GOPROXY 完全不可用(未设置且 go env 读取失败)时的 官方回退。
const ModulePath = "github.com/AoManoh/openpe"
ModulePath 是本项目的模块路径,@latest 查询与 go install 目标都由它派生。
Variables ¶
This section is empty.
Functions ¶
func IsNewer ¶
IsNewer 判断 latest 是否严格新于 current。任一方不是合法 semver(如归一 后的 "devel")返回 false——无法判定时既不提醒也不宣称"已是最新",交由 调用方按场景措辞。伪版本是合法的 semver 预发布,可正常参与比较。
func NoticeVersion ¶
func NoticeVersion(state CheckState, ok bool, current string, now time.Time, interval time.Duration) (string, bool)
NoticeVersion 决定 hook 披露行是否提醒:缓存存在、仍新鲜、且缓存的 latest 严格新于当前版本时返回该版本。其余情况(无缓存、过期、devel 当前版本、 已是最新)一律静默——提醒缺席不是失败。
func ResolveProxyBaseURL ¶
func ResolveProxyBaseURL() string
ResolveProxyBaseURL 解析实际要查询的 proxy 地址:环境变量 GOPROXY 优先, 未设置时读 `go env GOPROXY`(best-effort),再取列表中第一个可用条目; "off"/"direct" 不提供 /@latest 端点,跳过;全不可用回退官方 proxy。
func SaveState ¶
func SaveState(path string, state CheckState) error
SaveState 原子写入缓存(临时文件 + rename),避免并发 hook 读到半截 JSON。
Types ¶
type CheckState ¶
CheckState 是新版本检查的本地缓存:hook 披露行只读它,永不发网络请求。
func LoadState ¶
func LoadState(path string) (CheckState, bool)
LoadState 读取缓存;不存在或损坏返回 ok=false——缓存缺席不是错误,只是 "尚无检查结果"(提醒静默,业务契约 U2.2)。
type Client ¶
Client 查询 module proxy。BaseURL 为空时按 GOPROXY 解析;HTTPClient 为空时 使用带超时的默认客户端。测试用 httptest 地址注入 BaseURL。
type LatestInfo ¶
LatestInfo 是 module proxy /@latest 端点的 JSON 结构。