From a675c499c3fa208ad2325ad7e54f49ce4181ca67 Mon Sep 17 00:00:00 2001 From: mAi Date: Sat, 16 May 2026 13:38:52 +0200 Subject: [PATCH] fix: root-anchor mcables ignore pattern, commit cmd/mcables/main.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bare `mcables` pattern in .gitignore (line 11) and .dockerignore (line 18) was intended to ignore the built binary at the repo root, but without a leading slash it also matched the cmd/mcables/ directory. The result: cmd/mcables/main.go was never tracked in git, and fresh worktrees had to copy it from a sibling to build. - Change `mcables` → `/mcables` in both files (still ignores the root binary; no longer matches the cmd subdirectory). - Add cmd/mcables/main.go (copied from picasso's worktree, verified identical to head's main checkout). Verified: `git check-ignore cmd/mcables/main.go` returns not-ignored; a touched `./mcables` at the repo root is still ignored via `/mcables`. `go build ./...` clean. --- .dockerignore | 2 +- .gitignore | 2 +- cmd/mcables/main.go | 64 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 cmd/mcables/main.go diff --git a/.dockerignore b/.dockerignore index 577af91..1d6736b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -15,7 +15,7 @@ data # Build artefacts bin -mcables +/mcables # Editor cruft .vscode diff --git a/.gitignore b/.gitignore index 4ffd178..e48bf79 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ data/*.db-shm # Build artefacts bin/ -mcables +/mcables # Editor .vscode/ diff --git a/cmd/mcables/main.go b/cmd/mcables/main.go new file mode 100644 index 0000000..923ba27 --- /dev/null +++ b/cmd/mcables/main.go @@ -0,0 +1,64 @@ +package main + +import ( + "context" + "errors" + "log" + "net/http" + "os" + "os/signal" + "path/filepath" + "syscall" + "time" + + "mgit.msbls.de/m/mcables/internal/db" + "mgit.msbls.de/m/mcables/internal/server" + "mgit.msbls.de/m/mcables/web" +) + +func main() { + addr := envOr("MCABLES_ADDR", "0.0.0.0:7777") + dbPath := envOr("MCABLES_DB", "./data/mcables.db") + + if err := os.MkdirAll(filepath.Dir(dbPath), 0o755); err != nil { + log.Fatalf("mkdir data dir: %v", err) + } + + store, err := db.Open(dbPath) + if err != nil { + log.Fatalf("open db: %v", err) + } + defer store.Close() + + if err := db.Migrate(store.DB()); err != nil { + log.Fatalf("migrate: %v", err) + } + + srv := &http.Server{ + Addr: addr, + Handler: server.New(store, web.Static()), + ReadHeaderTimeout: 5 * time.Second, + } + + go func() { + log.Printf("mcables listening on %s (db=%s)", addr, dbPath) + if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { + log.Fatalf("listen: %v", err) + } + }() + + stop := make(chan os.Signal, 1) + signal.Notify(stop, os.Interrupt, syscall.SIGTERM) + <-stop + log.Printf("shutting down") + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + _ = srv.Shutdown(ctx) +} + +func envOr(key, fallback string) string { + if v := os.Getenv(key); v != "" { + return v + } + return fallback +}