feat(modules): port util + misc; expose Registry to handlers

Phase 5a of go-port-cloud-run plan: port first 2 of 4 modules (wordle/loldle
deferred to later phase). Port util.go, info.go, help.go, stickerid.go and
misc.go with tests. /help renders registry view; /info exposes chat/thread/
sender ids; /stickerid (private) returns bot-scoped file_ids; /ping writes
last_ping KV ms-epoch JSON for byte-parity, /mstats reads it, /fortytwo is
easter egg.

Registry-pointer-in-Deps required for /help to access module registry—pointer
captured at factory time, stable post-Build. Static factory catalog moved from
modules pkg to cmd/server to break import cycle. Code-review fixes applied in
same session: /info nil-deref guard, KV wire-format parity.
This commit is contained in:
tiennm99 committed 2026-05-09 08:24:52 +07:00
1 parent c7a631bffd
commit 45a57e1573
11 files changed
+597 -14

No files matched your search

+13 -1
View File
@@ -12,6 +12,8 @@ import (
"time"
"github.com/tiennm99/miti99bot-go/internal/modules"
"github.com/tiennm99/miti99bot-go/internal/modules/misc"
"github.com/tiennm99/miti99bot-go/internal/modules/util"
"github.com/tiennm99/miti99bot-go/internal/server"
"github.com/tiennm99/miti99bot-go/internal/storage"
"github.com/tiennm99/miti99bot-go/internal/telegram"
@@ -25,6 +27,16 @@ var secretEnvKeys = []string{
"CRON_SHARED_SECRET",
}
// factories is the static module catalog. Adding a new module is a one-line
// change here. Lives in main rather than the modules package to avoid an
// import cycle (modules → util → modules).
func factories() map[string]modules.Factory {
return map[string]modules.Factory{
"util": util.New,
"misc": misc.New,
}
}
// firestoreInitTimeout caps client construction at startup. Cloud Run cold
// start budget is 500ms target; firestore.NewClient is normally fast but
// network blips can make it hang. Fail fast and let Cloud Run restart us.
@@ -53,7 +65,7 @@ func main() {
log.Fatalf("telegram bot init: %v", err)
}
reg, err := modules.Build(cfg.Modules, modules.Factories, provider, cfg.ModuleEnv)
reg, err := modules.Build(cfg.Modules, factories(), provider, cfg.ModuleEnv)
if err != nil {
log.Fatalf("module registry: %v", err)
}