Dismiss function

This commit is contained in:
2026-05-11 06:57:07 -06:00
parent d4cc41df63
commit c48ee22f99
3 changed files with 119 additions and 7 deletions
+46
View File
@@ -0,0 +1,46 @@
package store
import (
"encoding/json"
"os"
)
type DismissedStore struct {
IDs map[string]bool `json:"ids"`
path string
}
func LoadDismissed(path string) (*DismissedStore, error) {
s := &DismissedStore{
IDs: make(map[string]bool),
path: path,
}
data, err := os.ReadFile(path)
if os.IsNotExist(err) {
return s, nil
}
if err != nil {
return nil, err
}
if err := json.Unmarshal(data, s); err != nil {
return nil, err
}
s.path = path
return s, nil
}
func (s *DismissedStore) Save() error {
data, err := json.MarshalIndent(s, "", " ")
if err != nil {
return err
}
return os.WriteFile(s.path, data, 0644)
}
func (s *DismissedStore) Dismiss(id string) {
s.IDs[id] = true
}
func (s *DismissedStore) IsDismissed(id string) bool {
return s.IDs[id]
}