feat: add Arch update helper and web UI
This commit is contained in:
43
internal/state/state.go
Normal file
43
internal/state/state.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Store struct {
|
||||
LastReminder time.Time `json:"last_reminder"`
|
||||
LastUpdateCount int `json:"last_update_count"`
|
||||
}
|
||||
|
||||
func Load(path string) (Store, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return Store{}, nil
|
||||
}
|
||||
if err != nil {
|
||||
return Store{}, err
|
||||
}
|
||||
|
||||
var store Store
|
||||
if err := json.Unmarshal(data, &store); err != nil {
|
||||
return Store{}, err
|
||||
}
|
||||
return store, nil
|
||||
}
|
||||
|
||||
func Save(path string, store Store) error {
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
data, err := json.MarshalIndent(store, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data = append(data, '\n')
|
||||
return os.WriteFile(path, data, 0o644)
|
||||
}
|
||||
Reference in New Issue
Block a user