This repository was archived by the owner on Oct 12, 2026. It is now read-only.
Repository navigation
chore: add CI, a licence, and the missing CNPJ validator - #5
Merged
Merged
Conversation
Three things a public repository needs and this one did not have, plus the validation everyone asks for first. CI. The tests existed and nothing ran them, so a pull request could break master in silence. The workflow checks gofmt, runs go vet, and runs the suite with -race — the cache and the HTTP handlers run concurrently, and a data race there would surface as a wrong validation result under load, which is the worst way for this particular service to fail. Licence. A public repository without one cannot legally be adopted by anyone. MIT, matching the other published work. .idea/ is removed and ignored. JetBrains project files are per-developer. CNPJ. Ported from the shared TypeScript validators so the two cannot disagree, with the weights and the "remainder below 2 yields zero" rule from the Receita Federal specification. It also joins the one-parameter-per-request guard — otherwise it would have been the hole through which two validations arrived at once — and the character guard from the sanitisation fix covers it, including the "/" that a CNPJ legitimately carries. Fourteen cases: real published CNPJs formatted, bare and spaced; both check digits wrong independently; wrong lengths; the repeated-digit values that pass the arithmetic and must be excluded by name; stray letters; and the handler route including the collision with cpf. The Swagger spec is regenerated so the new parameter appears in the UI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Repository hygiene
CI. The tests existed and nothing ran them — a pull request could break
masterin silence. The workflow checksgofmt, runsgo vet, and runs the suite with-race. The race detector matters here specifically: the cache and the HTTP handlers run concurrently, and a data race would surface as a wrong validation result under load, which is the worst way for this service to fail.Licence. A public repository without one cannot legally be adopted by anyone who finds it. MIT, matching the other published work.
.idea/removed and ignored. JetBrains project files are per-developer, not per-project.CNPJ
The validation people reach for first, and the one that was missing.
Ported from the shared TypeScript validators so the two implementations cannot drift, with the weights and the "remainder below 2 yields zero" rule from the Receita Federal specification.
Two details worth review:
validationCount. Without that,?cpf=…&cnpj=…would slip past the one-parameter-per-request rule — CNPJ would have been the hole through which two validations arrived at once./allowed, because a CNPJ legitimately carries one. The other documents do not, and still reject it.Tests
Fourteen new cases,
go test ./... -racegreen:00.000.000/0000-00and11.111.111/1111-11— these pass the check-digit arithmetic and have to be excluded by namecpf+cnpjcollision returningMULTIPLE_PARAMETERSThe Swagger spec is regenerated, so
cnpjappears in the UI.Note from production
With #4 deployed,
/healthnow answers:{"cache":"unreachable","status":"ok"}That confirms what the timings suggested: Redis is not connected on Render. The service degrades correctly — validation is pure computation — but the CPF path was paying 150–220 ms for a cache that never returned a hit. Worth either provisioning Redis or setting
REDIS_ADDR; the 150 ms cap from #4 bounds the damage until then.