mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-09-14 02:18:36 +00:00
Phase 6 of the 2026-05-09 review remediation plan. Bundle of small
hygiene fixes — none individually urgent but better folded together
than scattered across follow-ups.
- .golangci.yml: enable errcheck/govet/gosec/staticcheck/unused/
ineffassign/gocyclo/misspell/revive. Tuned to the codebase style
(no universal exported-doc requirement, gocyclo cap at 20 to
accommodate handler dispatch). 0 issues across the tree.
- ci.yml: add golangci-lint job + govulncheck (informational).
- Defensive guards:
- registry.go: Module.Name mismatch now errors at Build instead of
silently overwriting (TestBuild_RejectsFactoryNameMismatch).
- cmd/server/main.go: PORT env validated numerically + 0..65535.
- firestore_provider.go: For() re-validates module name; invalid
names return an invalidStore whose every op errors with
ErrInvalidModuleName.
- Dead code removal:
- wordle: gameTTLSeconds const + pickDaily/hashDJB2/todayUTC
helpers + their tests deleted (pickDaily was unused;
daily.go renamed pick_random.go).
- Dependency: golang.org/x/net v0.52.0 -> v0.54.0 (resolves
GO-2026-4918 HTTP/2 infinite-loop CVE).
- Deferred from the original phase plan: Docker digest pinning
(Dependabot handles), per-handler file splits (largest file 279 LOC;
splits would churn for marginal gain).
go test -race -count=1 ./... clean (15 packages); golangci-lint run
clean (0 issues).
27 lines
939 B
Go
27 lines
939 B
Go
package wordle
|
|
|
|
import (
|
|
"errors"
|
|
"math/rand"
|
|
)
|
|
|
|
// errEmptyWordList is returned by pickers when the dictionary is empty —
|
|
// callers (Init) should fail fast rather than spin a game with no answers.
|
|
var errEmptyWordList = errors.New("wordle: word list is empty")
|
|
|
|
// pickRandom is the picker handlers actually use today. Uniform random pick.
|
|
// rng allows tests to inject a deterministic source. When rng is nil we fall
|
|
// through to math/rand's package-level Intn, which IS goroutine-safe via an
|
|
// internal mutex on the global Source — important because the bot dispatcher
|
|
// runs each Telegram update in its own goroutine and concurrent /wordle_new
|
|
// calls would otherwise race on a shared *rand.Rand.
|
|
func pickRandom(words []string, rng *rand.Rand) (string, error) {
|
|
if len(words) == 0 {
|
|
return "", errEmptyWordList
|
|
}
|
|
if rng != nil {
|
|
return words[rng.Intn(len(words))], nil
|
|
}
|
|
return words[rand.Intn(len(words))], nil
|
|
}
|