From c895a67c4b6c6c3f9186b6157ad60afca5b908e5 Mon Sep 17 00:00:00 2001 From: sysops Date: Thu, 27 Aug 2026 17:27:59 +0200 Subject: [PATCH] core: initial Go module skeleton (config, db pool, tenant registry migration) --- .gitignore | 2 ++ DEVLOG.md | 46 +++++++++++++++++++++++++++++ cmd/core/main.go | 33 +++++++++++++++++++++ go.mod | 5 ++++ internal/config/config.go | 29 ++++++++++++++++++ internal/db/db.go | 11 +++++++ migrations/0001_tenant_registry.sql | 10 +++++++ 7 files changed, 136 insertions(+) create mode 100644 .gitignore create mode 100644 DEVLOG.md create mode 100644 cmd/core/main.go create mode 100644 go.mod create mode 100644 internal/config/config.go create mode 100644 internal/db/db.go create mode 100644 migrations/0001_tenant_registry.sql diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ac00d6f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.log +.env diff --git a/DEVLOG.md b/DEVLOG.md new file mode 100644 index 0000000..7178fe5 --- /dev/null +++ b/DEVLOG.md @@ -0,0 +1,46 @@ +# code – Dev Log + +## 2026-08-27 17:17 – 17:18 (0m) +**Beschreibung:** Claude Code Session +**Projekt:** nexarch + +### Commits +Keine Commits in dieser Session. + +### Geänderte Dateien +Keine Änderungen ermittelbar. + +--- +## 2026-08-27 17:21 – 17:21 (0m) +**Beschreibung:** Claude Code Session +**Projekt:** code + +### Commits +Keine Commits in dieser Session. + +### Geänderte Dateien +Keine Änderungen ermittelbar. + +--- +## 2026-08-27 17:22 – 17:22 (0m) +**Beschreibung:** Claude Code Session +**Projekt:** code + +### Commits +Keine Commits in dieser Session. + +### Geänderte Dateien +Keine Änderungen ermittelbar. + +--- +## 2026-08-27 17:23 – 17:25 (2m) +**Beschreibung:** Claude Code Session +**Projekt:** code + +### Commits +Keine Commits in dieser Session. + +### Geänderte Dateien +Keine Änderungen ermittelbar. + +--- diff --git a/cmd/core/main.go b/cmd/core/main.go new file mode 100644 index 0000000..f8e362e --- /dev/null +++ b/cmd/core/main.go @@ -0,0 +1,33 @@ +package main + +import ( + "context" + "log" + "net/http" + + "gitea.perlbach24.de/scripte/nexarch/internal/config" + "gitea.perlbach24.de/scripte/nexarch/internal/db" +) + +func main() { + cfg, err := config.Load() + if err != nil { + log.Fatalf("config: %v", err) + } + + pool, err := db.Connect(context.Background(), cfg.RegistryDSN) + if err != nil { + log.Fatalf("db: %v", err) + } + defer pool.Close() + + mux := http.NewServeMux() + mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + }) + + log.Printf("nexarch-core listening on %s", cfg.ListenAddr) + if err := http.ListenAndServe(cfg.ListenAddr, mux); err != nil { + log.Fatalf("server: %v", err) + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..75a79b7 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module gitea.perlbach24.de/scripte/nexarch + +go 1.22 + +require github.com/jackc/pgx/v5 v5.6.0 diff --git a/internal/config/config.go b/internal/config/config.go new file mode 100644 index 0000000..d51dc5f --- /dev/null +++ b/internal/config/config.go @@ -0,0 +1,29 @@ +package config + +import ( + "fmt" + "os" +) + +// Config holds startup configuration for the core module. +// RegistryDSN points at the control-plane registry DB (tenant list, +// connection info, superadmin accounts) — see nexarch-state.json +// multi_tenancy: Modell C (physisch getrennte DB pro Mandant). +type Config struct { + ListenAddr string + RegistryDSN string +} + +func Load() (Config, error) { + dsn := os.Getenv("NEXARCH_REGISTRY_DSN") + if dsn == "" { + return Config{}, fmt.Errorf("NEXARCH_REGISTRY_DSN not set") + } + + addr := os.Getenv("NEXARCH_LISTEN_ADDR") + if addr == "" { + addr = ":8080" + } + + return Config{ListenAddr: addr, RegistryDSN: dsn}, nil +} diff --git a/internal/db/db.go b/internal/db/db.go new file mode 100644 index 0000000..4a97193 --- /dev/null +++ b/internal/db/db.go @@ -0,0 +1,11 @@ +package db + +import ( + "context" + + "github.com/jackc/pgx/v5/pgxpool" +) + +func Connect(ctx context.Context, dsn string) (*pgxpool.Pool, error) { + return pgxpool.New(ctx, dsn) +} diff --git a/migrations/0001_tenant_registry.sql b/migrations/0001_tenant_registry.sql new file mode 100644 index 0000000..3b01739 --- /dev/null +++ b/migrations/0001_tenant_registry.sql @@ -0,0 +1,10 @@ +-- Control-plane registry: tenant list + connection info (Modell C). +-- Core TEN-01 (siehe core-kanban). +CREATE TABLE tenants ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + slug TEXT NOT NULL UNIQUE, + name TEXT NOT NULL, + db_dsn TEXT NOT NULL, + status TEXT NOT NULL DEFAULT 'active', + created_at TIMESTAMPTZ NOT NULL DEFAULT now() +);