feat(api): M4.2 — REST surface + pgx Postgres store + OpenAPI 3.1
Full M4.2 deliverable: 16 endpoints (tenants CRUD + lifecycle, catalog, entitlements, API keys with argon2 hashing, audit append + filter), Store interface with pgx-backed Postgres + in-memory parallel implementations exercised by the same eachStore harness, openapi.yaml at 3.1 with kin-openapi contract test. M4.3 adds auth. Refs: M4.2
This commit was merged in pull request #7.
This commit is contained in:
+32
-3
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"gitea.meghsakha.com/platform/tenant-registry/internal/config"
|
||||
"gitea.meghsakha.com/platform/tenant-registry/internal/server"
|
||||
"gitea.meghsakha.com/platform/tenant-registry/internal/store"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -24,10 +25,27 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
mux := server.NewRouter(cfg, logger)
|
||||
bootCtx, cancelBoot := context.WithTimeout(context.Background(), 15*time.Second)
|
||||
defer cancelBoot()
|
||||
|
||||
var s store.Store
|
||||
if cfg.DatabaseURL == "" {
|
||||
slog.Warn("DATABASE_URL not set — running with in-memory store (dev only)")
|
||||
s = store.NewMemory()
|
||||
} else {
|
||||
pg, err := store.NewPostgres(bootCtx, cfg.DatabaseURL)
|
||||
if err != nil {
|
||||
slog.Error("postgres connect failed", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
s = pg
|
||||
}
|
||||
defer s.Close()
|
||||
|
||||
handler := server.NewRouter(&server.Server{Cfg: cfg, Log: logger, Store: s})
|
||||
srv := &http.Server{
|
||||
Addr: cfg.Addr,
|
||||
Handler: mux,
|
||||
Handler: handler,
|
||||
ReadTimeout: 10 * time.Second,
|
||||
WriteTimeout: 30 * time.Second,
|
||||
IdleTimeout: 60 * time.Second,
|
||||
@@ -37,7 +55,7 @@ func main() {
|
||||
defer stop()
|
||||
|
||||
go func() {
|
||||
slog.Info("tenant-registry listening", "addr", cfg.Addr, "env", cfg.Env)
|
||||
slog.Info("tenant-registry listening", "addr", cfg.Addr, "env", cfg.Env, "store", storeKind(s))
|
||||
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
slog.Error("server crashed", "err", err)
|
||||
os.Exit(1)
|
||||
@@ -54,3 +72,14 @@ func main() {
|
||||
}
|
||||
slog.Info("bye")
|
||||
}
|
||||
|
||||
func storeKind(s store.Store) string {
|
||||
switch s.(type) {
|
||||
case *store.Memory:
|
||||
return "memory"
|
||||
case *store.Postgres:
|
||||
return "postgres"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user