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

remote

package
v1.7.0 Latest Latest
Warning

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

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

Documentation

Overview

Package remote 提供远程 skill 市场功能。

通过 GitHub Contents API 拉取 goink-skills 仓库的 index.json 和 skill 文件, 支持本地缓存、安装到用户层或小说层 skill 目录,并触发热重载。 网络错误按语义类别(githubapi.Kind)透传给调用方,便于前端给出针对性提示。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IndexFile

type IndexFile struct {
	Updated string            `json:"updated"` // ISO 8601 UTC 时间戳
	Skills  []RemoteSkillMeta `json:"skills"`
}

IndexFile 对应远程仓库 goink-skills/index.json 的结构。 该文件由仓库内的 scripts/generate-index.py 生成。

type RemoteSkillMeta

type RemoteSkillMeta struct {
	Name        string `json:"name"`        // skill 名称,同时作为文件名(不含 .md 后缀)
	Description string `json:"description"` // 简要描述
	Category    string `json:"category"`    // 分类
	Mode        string `json:"mode"`        // 触发模式:auto / manual / always
	Author      string `json:"author"`      // 作者
	Version     int    `json:"version"`     // 版本号(整数,缺失时默认 1)
	File        string `json:"file"`        // 文件名,如 "my-skill.md"
}

RemoteSkillMeta 是远程 skill 的元数据,字段对齐 generate-index.py 输出。

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service 提供远程 skill 市场的业务逻辑:列表、查看、安装。

持有 GitHub API 客户端、skill 仓库热重载句柄、目录解析器和内存缓存。 网络错误透传 *githubapi.Error,调用方可按 Kind 分类处理。

func NewService

func NewService(skillStore *skill.Store, logger *slog.Logger) *Service

NewService 创建生产环境使用的 Service。 skillStore 传入 *skill.Store,内部用 githubapi.NewClient() 拉取远程内容。 缓存为进程内内存缓存,TTL 由 cacheTTL 控制,进程重启后失效。

func (*Service) GetRemoteSkillContent

func (s *Service) GetRemoteSkillContent(ctx context.Context, name string) (string, error)

GetRemoteSkillContent 拉取指定 skill 的 markdown 原文内容。 路径形如 "skills/{name}.md"。

func (*Service) InstallRemoteSkill

func (s *Service) InstallRemoteSkill(ctx context.Context, name, target string, novelID int64, expectedContent string) error

InstallRemoteSkill 将指定远程 skill 安装到目标层(user 或 novel)。

流程:

  1. 拉取 skill 内容
  2. 解析目标目录(user → ~/.goink/skills/,novel → {novel_dir}/skills/)
  3. MkdirAll + WriteFile 写入 {name}.md
  4. 触发热重载(失败只 Warn,不返回 error,因为文件已成功写入)

不做存在性判断,前端弹确认框处理覆盖语义。 写入前仍须在进程锁内比较前端确认的内容,阻止确认期间发生的覆盖。

func (*Service) ListRemoteSkills

func (s *Service) ListRemoteSkills(ctx context.Context, forceRefresh bool) ([]RemoteSkillMeta, error)

ListRemoteSkills 列出远程仓库的全部 skill 元数据。

forceRefresh=false 时优先使用内存缓存;缓存不存在/已过期或 forceRefresh=true 时 调 GitHub API 拉取 index.json 并更新内存缓存。 错误用 fmt.Errorf("remote: ...: %w", err) 包装,保留 *githubapi.Error 的 Unwrap 链。

并发安全:cacheMu 保护 cacheSkills/cacheAt 读写,调 API 时不持锁。

Jump to

Keyboard shortcuts

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