From 03bf327f6bd595068465e44d943c881247ac4f37 Mon Sep 17 00:00:00 2001 From: poslop Date: Wed, 9 Sep 2026 02:04:03 -0500 Subject: [PATCH] fix: anchor gitignore binary pattern, track cmd/palette --- .gitignore | 2 +- cmd/palette/main.go | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 cmd/palette/main.go diff --git a/.gitignore b/.gitignore index e4f2435..a1acada 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -palette +/palette palette.db palette.db-shm palette.db-wal diff --git a/cmd/palette/main.go b/cmd/palette/main.go new file mode 100644 index 0000000..2807582 --- /dev/null +++ b/cmd/palette/main.go @@ -0,0 +1,48 @@ +// Command palette is the palette pastebin server entrypoint: flag parsing +// and wiring of the store, API, and web packages. +package main + +import ( + "log" + "os" + "net/http" + "time" + + "palette/internal/api" + "palette/internal/store" + "palette/internal/web" +) + +func main() { + // #40: --reset-admin-key regenerates the admin key and exits. + if len(os.Args) > 1 && os.Args[1] == "--reset-admin-key" { + api.HandleResetAdminKey(api.EnvOr("PALETTE_DB", "palette.db")) + return + } + cfg := api.Config{ + Addr: api.EnvOr("PALETTE_ADDR", ":8080"), + DBPath: api.EnvOr("PALETTE_DB", "palette.db"), + MaxTextBytes: int64(api.EnvIntOr("PALETTE_MAX_TEXT", 5*1024*1024)), + MaxItemBytes: int64(api.EnvIntOr("PALETTE_MAX_ITEM", 25*1024*1024)), + } + st, err := store.OpenStore(cfg.DBPath) + if err != nil { + log.Fatal(err) + } + + adminKey, err := api.ResolveAdminKey(cfg.DBPath) + if err != nil { + log.Fatal(err) + } + ss := api.LoadSettingsStore(cfg.DBPath, cfg) + + st.StartSweeper(time.Minute, ss.Get().CustomSlugReservationDays) + + ui, err := web.New() + if err != nil { + log.Fatal(err) + } + srv := api.NewServer(st, cfg, ui, ss, adminKey) + log.Printf("palette listening on %s", cfg.Addr) + log.Fatal(http.ListenAndServe(cfg.Addr, srv.Routes())) +}