route

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package route 管理自动选线路由缓存(~/.javdb-cli/route.json)的原子读写。

schema 只保存 {"host":"https://..."},不保存 proxy、token、时间戳、测速历史或 fallback 状态。缺失文件是"无缓存";损坏、未知字段、空 host 或非法 URL 都显式报错,不伪装为 miss。

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyHost = errors.New("route cache host is empty")

ErrEmptyHost 表示缓存 host 为空。

Functions

func Save

func Save(path string, doc Document) error

Save 原子写入 route cache:同目录私有临时文件、完整写入、Sync、rename 替换,目标 0600。 任一步失败都清理临时文件并显式返回错误,不留下半成品。

func ValidateHost

func ValidateHost(host string) error

ValidateHost 校验 host 为不含 query/fragment 的绝对 http/https URL。

Types

type Document

type Document struct {
	Host string `json:"host"`
}

Document 是 route.json 的磁盘 schema。

func Load

func Load(path string) (Document, bool, error)

Load 读取 route cache。缺失文件返回 ok=false、无错误;损坏 JSON、未知字段、空 host 或 非法 URL 返回显式错误。

Jump to

Keyboard shortcuts

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