Storage Layer
Responsibility
internal/store defines the Store interface and two implementations:
MemoryStore (dev/tests) and PostgresStore (production). Handlers depend on
the interface, so storage is swappable and degraded mode is possible.
Store interface
Methods: Migrate, Create, Get, List, Update, Delete, Close.
Errors use sentinel values from internal/model (ErrNotFound,
ErrAlreadyExists).
MemoryStore
In-memory map guarded by sync.RWMutex. Migrate and Close are no-ops.
Used for STORE=memory and for tests. Not persistent across restarts.
PostgresStore
NewPostgresopens apgxpool.Pooland pings it.Migratecreates theflagstable if missing.- CRUD via parameterized SQL; unique violations map to
ErrAlreadyExists;pgx.ErrNoRowsmaps toErrNotFound. Closecloses the pool.
Degraded mode
If connection or migration fails, main.go leaves st nil, sets readiness
false, and omits flag routes. The process still serves health and metrics.
Related
openwiki/api/control-plane-api.mdopenwiki/operations/health-and-readiness.mdopenwiki/runtime/lifecycle.mdopenwiki/testing/test-strategy.md