mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-07-28 18:21:43 +00:00
3aab95daf0e77c15b77ef5ae4cc9e2799137bb5b
Phase 11 partial of the go-port-cloud-run plan. Code-side
observability hooks ready ahead of Phase 01 GCP rollout.
- internal/server/log_middleware.go: HTTP middleware that wraps the
router and emits {msg:"req", method, path, status, ms} per
request. statusRecorder defaults to 200 when the inner handler
doesn't call WriteHeader (Go writes 200 implicitly on first body
write). Wired into server.New so /, /webhook, /cron/* all log.
- internal/metrics/counters.go: in-memory Registry with
IncCommand/IncError/IncAI. Atomic Int64 per name + RWMutex on the
map; steady-state increments are mutex-free. Periodic Run flushes
via the project logger every 60s and one final flush on ctx done.
Empty flush is silent (no-noise default).
- Dispatcher instrumented: every command invocation calls
metrics.IncCommand; every handler error calls
metrics.IncError("handler-error"). Logger keeps the full error
detail; counters keep the rate.
- cmd/server/main.go: go metrics.Run(rootCtx) so the flush loop
cancels with SIGTERM and emits the trailing window before exit.
Test coverage: 12 new tests (7 metrics, 3 middleware, 2 default-
registry round-trip). go test -race -count=1 ./... clean
(20 packages); golangci-lint clean.
Soak / cold-start measurement / log-based metrics setup deferred to
post-deployment (Phase 01 prerequisite).
miti99bot-go
Plug-n-play Telegram bot framework in Go, deployed on Google Cloud Run with Firestore + Gemini. Free-tier port of miti99bot.
Status
Early scaffolding. See plans/260508-2222-go-port-cloud-run/plan.md for the full roadmap.
| Phase | What | Status |
|---|---|---|
| 01 | GCP setup, Cloud Run baseline | pending |
| 02 | Repo bootstrap + webhook skeleton | partial (local pieces done; Cloud Run deploy deferred to Phase 01) |
| 03 | Module framework + KVStore | done |
| 04+ | Firestore, modules, cron, CI/CD, cutover | pending |
Layout
cmd/server/ entrypoint
internal/server/ HTTP routes (/, /webhook, /cron/{name})
internal/telegram/ Telegram webhook + bot wrapper
internal/modules/ Module framework, registry, dispatchers
internal/storage/ KVStore interface, in-memory impl, prefix wrapper
Run locally
TELEGRAM_BOT_TOKEN=… \
TELEGRAM_WEBHOOK_SECRET=local \
PORT=8080 \
MODULES= \
go run ./cmd/server
End-to-end smoke test against a Telegram dev bot requires ngrok (local) or a Cloud Run deployment. The dev bot is created manually; token is injected via env vars only.
Test
go vet ./...
go test ./...
Build
docker build -t miti99bot-go .
The image is multi-stage (golang:1.23-alpine → gcr.io/distroless/static:nonroot); resulting image is ~15 MiB.
License
Description
Plug-n-play Telegram bot framework on Cloudflare Workers with grammY. Modules load via env var, three command visibility levels, KV storage behind a swappable interface.
bot-frameworkcoolifycrongeminigoleague-of-legendslong-pollingmongodbmongodb-atlaspaper-tradingself-hostedtelegramtelegram-botwordleworld-cup
Readme
Apache-2.0
3.6 MiB
Languages
Go
99.9%