auth

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package auth stores multi-account JavDB credentials under ~/.javdb-cli/auth.json.

Index

Constants

This section is empty.

Variables

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

ErrNotFound is returned when an account lookup fails.

Functions

func Open

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

Open loads (or creates empty) the store at path.

func Save

func Save(path string, s *Store) error

Save writes the store atomically with 0600 permissions where the platform supports POSIX permission bits.

Types

type Account

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

Account is one saved login (password stored by design).

type FileStore

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

FileStore is a path-backed store with a mutex for CLI use.

func (*FileStore) Commit

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

Commit saves s to the file store path.

type Store

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

Store is the on-disk multi-account file.

func Load

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

Load reads path; missing file returns empty store.

func (*Store) Default

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

Default returns the default account, or ErrNotFound.

func (*Store) Get

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

Get finds an account by user id.

func (*Store) Remove

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

Remove deletes by user id. If it was default, clears or reassigns default.

func (*Store) UpdateToken

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

UpdateToken replaces the token for an account.

func (*Store) Upsert

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

Upsert inserts or replaces by user_id. If setDefault, updates default_user_id.

func (*Store) Use

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

Use sets the default user id.

Jump to

Keyboard shortcuts

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