Files
supermarket/internal/store/dismissed.go
T
2026-05-11 06:57:07 -06:00

47 lines
782 B
Go

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]
}