auth

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: 6 Imported by: 0

Documentation

Overview

Package auth 持久化 ~/.javdb-cli/auth.json 中的多账户认证资料。

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("account not found")

ErrNotFound 表示账户查询没有匹配项。

Functions

func Open

func Open(path string) (*FileStore, *Store, error)

Open 加载指定路径的 store;不存在时返回空 store 与已绑定的 FileStore。

func Save

func Save(path string, store *Store) error

Save 以原有的临时文件 + rename 方式保存 0600 认证文件。

Types

type Account

type Account struct {
	UserID   int64  `json:"user_id"`
	Username string `json:"username"`
	Password string `json:"password"`
	Token    string `json:"token"`
}

Account 表示一个已保存的登录账户;密码按现有格式明文保存。

type FileStore

type FileStore struct {
	Path string
	// contains filtered or unexported fields
}

FileStore 将文件路径与互斥提交操作绑定,供 CLI 使用。

func (*FileStore) Commit

func (f *FileStore) Commit(store *Store) error

Commit 将 store 保存到绑定路径。

type Store

type Store struct {
	DefaultUserID int64     `json:"default_user_id"`
	Accounts      []Account `json:"accounts"`
}

Store 是磁盘上的多账户 JSON 文档。

func Load

func Load(path string) (*Store, error)

Load 读取认证文件;文件不存在时返回空 store。

func (*Store) Default

func (s *Store) Default() (Account, error)

Default 返回默认账户;未设置默认账户时仅在恰有一个账户的情况下推断。

func (*Store) Get

func (s *Store) Get(userID int64) (Account, error)

Get 按 user id 查找账户。

func (*Store) Remove

func (s *Store) Remove(userID int64) error

Remove 删除账户;删除默认账户时沿用原有的首账户重选规则。

func (*Store) UpdateToken

func (s *Store) UpdateToken(userID int64, token string) error

UpdateToken 替换指定账户的 token。

func (*Store) Upsert

func (s *Store) Upsert(account Account, setDefault bool)

Upsert 按 user_id 插入或替换账户;setDefault 为 true 时同步默认账户。

func (*Store) Use

func (s *Store) Use(userID int64) error

Use 将指定账户设为默认账户。

Jump to

Keyboard shortcuts

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