refactor: simplify config into a single load/save with defaults resolved at load time
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user