auth

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultAuthFileMode = constants.PrivateFileMode

Variables

This section is empty.

Functions

func AuthFilePath

func AuthFilePath() (string, error)

func IsLegacySchemaError

func IsLegacySchemaError(err error) bool

func IsMissingRefreshTokenError added in v0.4.0

func IsMissingRefreshTokenError(err error) bool

IsMissingRefreshTokenError 只暴露安全分类,不携带 token 或文件内容。

func SaveAuthStore

func SaveAuthStore(path string, store AuthStore) error

func SetAuthFilePathForTest

func SetAuthFilePathForTest(authPath string) func()

func SetReadAuthStoreFileForTest added in v0.4.0

func SetReadAuthStoreFileForTest(path string, read func(string) ([]byte, error)) func()

SetReadAuthStoreFileForTest 仅为跨平台本地状态错误测试拦截指定 auth path。 其他路径始终使用 os.ReadFile。hook 生命周期由互斥锁串行化,同一路径测试不得 并行;调用方必须用 t.Cleanup 执行返回的恢复函数。

func SetWriteAuthStoreFileForTest added in v0.4.0

func SetWriteAuthStoreFileForTest(path string, write func(string, []byte) error) func()

SetWriteAuthStoreFileForTest 仅为本地状态原子失败测试拦截指定 auth path。 hook 在编码与完整 store 校验之后、真实原子写入之前执行;调用方必须用 t.Cleanup 执行返回的恢复函数,且不得并行使用同一路径。

func WritePrivateFile

func WritePrivateFile(path string, body []byte) error

Types

type Account

type Account struct {
	RefreshToken string `json:"refresh_token"`
	UserID       int64  `json:"user_id,omitempty"`
	Username     string `json:"username,omitempty"`
	// PremiumStatus 仅缓存由 App profile 验证过的会员状态;nil 代表从未验证。
	PremiumStatus          *bool      `json:"premium_status,omitempty"`
	PremiumStatusCheckedAt *time.Time `json:"premium_status_checked_at,omitempty"`
}

func SelectAuthAccount

func SelectAuthAccount(store AuthStore, requestedUserID int64) (int64, Account, bool)

type AuthStore

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

func LoadAuthStore

func LoadAuthStore(path string) (AuthStore, error)

func (AuthStore) Get

func (s AuthStore) Get(userID int64) (int, Account, bool)

func (AuthStore) Has

func (s AuthStore) Has(userID int64) bool

func (*AuthStore) Remove

func (s *AuthStore) Remove(userID int64) bool

func (*AuthStore) Upsert

func (s *AuthStore) Upsert(acct Account)

func (AuthStore) UserIDs

func (s AuthStore) UserIDs() []int64

type LegacySchemaError

type LegacySchemaError struct {
	Field string
}

func (LegacySchemaError) Error

func (e LegacySchemaError) Error() string

type SaveCommitOutcome added in v0.4.0

type SaveCommitOutcome string

SaveCommitOutcome 标识 auth store 的目标文件 replacement 是否已提交。

const (
	SaveCommitOutcomeUnknown      SaveCommitOutcome = "unknown"
	SaveCommitOutcomeNotCommitted SaveCommitOutcome = "not_committed"
	SaveCommitOutcomeCommitted    SaveCommitOutcome = "committed"
)

func SaveAuthStoreWithOutcome added in v0.4.0

func SaveAuthStoreWithOutcome(path string, store AuthStore) (SaveCommitOutcome, error)

SaveAuthStoreWithOutcome 保存 auth store,并在失败时返回稳定的 commit outcome。 not_committed 表示新内容未替换目标;committed 表示 replacement 已完成,但后续 cleanup 或 durability 步骤失败,调用方必须重新加载目标确认当前状态。

Jump to

Keyboard shortcuts

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