From 9eb5ab1818b6b19501fd7209db1987c9e06cc919 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Tue, 9 Jun 2026 05:59:20 -0400 Subject: first commit --- internal/object/item_store.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 internal/object/item_store.go (limited to 'internal/object/item_store.go') diff --git a/internal/object/item_store.go b/internal/object/item_store.go new file mode 100644 index 0000000..6d62143 --- /dev/null +++ b/internal/object/item_store.go @@ -0,0 +1,38 @@ +package object + +import ( + "fmt" + "os" + "path/filepath" + + "gopkg.in/yaml.v3" +) + +type ItemStore struct { + dataDir string + cache map[string]*ItemDef +} + +func NewItemStore(dataDir string) *ItemStore { + return &ItemStore{ + dataDir: dataDir, + cache: make(map[string]*ItemDef), + } +} + +func (s *ItemStore) Load(id string) (*ItemDef, error) { + if def, ok := s.cache[id]; ok { + return def, nil + } + path := filepath.Join(s.dataDir, "items", id+".yaml") + data, err := os.ReadFile(path) + if err != nil { + return nil, fmt.Errorf("read item %s: %w", id, err) + } + var def ItemDef + if err := yaml.Unmarshal(data, &def); err != nil { + return nil, fmt.Errorf("parse item %s: %w", id, err) + } + s.cache[id] = &def + return &def, nil +} -- cgit v1.2.3