diff options
| author | historia <[not public]> | 2026-06-09 05:59:20 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-06-09 05:59:20 -0400 |
| commit | 9eb5ab1818b6b19501fd7209db1987c9e06cc919 (patch) | |
| tree | 76e046b0bf611dfe939a8c8f6507467de2e9e20f /internal/object/store.go | |
| download | thehouseoficarus-9eb5ab1818b6b19501fd7209db1987c9e06cc919.tar.gz | |
first commit
Diffstat (limited to 'internal/object/store.go')
| -rw-r--r-- | internal/object/store.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/internal/object/store.go b/internal/object/store.go new file mode 100644 index 0000000..a884601 --- /dev/null +++ b/internal/object/store.go @@ -0,0 +1,38 @@ +package object + +import ( + "fmt" + "os" + "path/filepath" + + "gopkg.in/yaml.v3" +) + +type ObjectStore struct { + dataDir string + cache map[string]*ObjectDef +} + +func NewObjectStore(dataDir string) *ObjectStore { + return &ObjectStore{ + dataDir: dataDir, + cache: make(map[string]*ObjectDef), + } +} + +func (s *ObjectStore) Load(id string) (*ObjectDef, error) { + if def, ok := s.cache[id]; ok { + return def, nil + } + path := filepath.Join(s.dataDir, "objects", fmt.Sprintf("%s.yaml", id)) + data, err := os.ReadFile(path) + if err != nil { + return nil, fmt.Errorf("read object %s: %w", id, err) + } + var def ObjectDef + if err := yaml.Unmarshal(data, &def); err != nil { + return nil, fmt.Errorf("parse object %s: %w", id, err) + } + s.cache[id] = &def + return &def, nil +} |
