gen

command
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2026 License: ISC Imports: 10 Imported by: 0

README

Regenerating the country table

countries_data.go is generated, not edited. It is derived from the ISO 3166-1 list published with UN M49 region codes:

https://github.com/lukes/ISO-3166-Countries-with-Regional-Codes

To regenerate after an ISO revision, from the repository root:

go generate ./...
go test ./...

That fetches the current upstream CSV. To regenerate from a local copy instead, which is what you want when reviewing a change to the data:

go run ./internal/gen -source all.csv -o countries_data.go

The output is formatted with go/format, so there is no gofmt step, and the generator fails rather than writing a table it cannot vouch for: an unknown region, a duplicate country, a missing column, or a membership entry naming a country the source does not list.

EU and EEA membership live in main.go, because they are political facts rather than ISO ones and the CSV does not carry them. The generator checks their cardinality and the package tests check it again (27 and 30), so a bad edit fails rather than shipping.

The generator has its own tests, which build small CSV sources in memory and serve them over httptest rather than reaching for the network:

go test ./internal/gen/

main itself is not covered -- it is flag parsing and log.Fatal -- and neither are the two guards on the membership list sizes, which can only fire if the lists in this file are edited wrongly and which TestMembershipListsAreTheRightSize asserts directly instead.

Documentation

Overview

Command gen writes countries_data.go from the ISO 3166-1 list published with UN M49 region codes.

It reads the CSV from a local path or, by default, from the upstream URL, and formats its output with go/format so the result needs no gofmt pass:

go run ./internal/gen -o countries_data.go
go run ./internal/gen -source all.csv -o countries_data.go

EU and EEA membership are political facts the CSV does not carry, so they are maintained here. The package tests assert their cardinality, which is what keeps a bad edit from shipping quietly.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL