refactor: simplify config into a single load/save with defaults resolved at load time

This commit is contained in:
2026-06-12 01:21:04 +02:00
parent 7b8202b50b
commit 6421c28191
7 changed files with 132 additions and 187 deletions
+4
View File
@@ -13,6 +13,8 @@ type Session struct {
Token string `json:"token"`
}
// LoadSession reads the session token from disk. If no session file
// exists, an empty Session is returned (Token will be "").
func LoadSession() (*Session, error) {
sessionRoot, err := FindDataRoot(".local", "share")
if err != nil {
@@ -34,6 +36,7 @@ func LoadSession() (*Session, error) {
return &s, nil
}
// Save writes the session token to disk with restrictive permissions (0600).
func (s *Session) Save() error {
if err := os.MkdirAll(filepath.Dir(s.path), 0700); err != nil {
return err
@@ -45,6 +48,7 @@ func (s *Session) Save() error {
return os.WriteFile(s.path, data, 0600)
}
// ClearSession deletes the session file from disk.
func (s *Session) ClearSession() error {
err := os.Remove(s.path)
if os.IsNotExist(err) {