go-countries
๐ Go package providing comprehensive country data in all standard ISO formats
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
โCITATION.cff file
Found CITATION.cff file -
โcodemeta.json file
Found codemeta.json file -
โ.zenodo.json file
Found .zenodo.json file -
โDOI references
-
โAcademic publication links
-
โCommitters with academic emails
-
โInstitutional organization owner
-
โJOSS paper metadata
-
โScientific vocabulary similarity
Low similarity (8.7%) to scientific vocabulary
Keywords
Keywords from Contributors
Repository
๐ Go package providing comprehensive country data in all standard ISO formats
Basic Info
Statistics
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
- Releases: 24
Topics
Metadata Files
README.md
๐บ๏ธ goโcountries
Go package providing comprehensive country data in all standard ISO formats
| CI / CD | Quality & Security | Docs & Meta | Community |
|---|---|---|---|
|
|
|
|
|
๐๏ธ Table of Contents
- Installation
- Usage
- Documentation
- Examples & Tests
- Benchmarks
- Code Standards
- AI Compliance
- Credits
- Maintainers
- Contributing
- License
๐ฆ Installation
go-countries requires a supported release of Go.
bash script
go get -u github.com/mrz1836/go-countries
๐ก Usage
Here is a basic example of how to use go-countries in your Go project:
```go package main
import ( "fmt" "github.com/mrz1836/go-countries" )
func main() { country := countries.GetByAlpha2(countries.Alpha2US) if country != nil { fmt.Printf("Country: %s, Capital: %s\n", country.Name, country.Capital) } else { fmt.Println("Country not found") } } ```
- Explore additional usage examples for practical integration patterns
- Review benchmark results to assess performance characteristics
- Examine the comprehensive test suite for validation and coverage
- Inspect the code generator for details on data sources and the build process
๐ Documentation
View the generated documentation
Heads up!
go-countriesis intentionally light on dependencies. The only external package it uses is the excellenttestifysuiteโand that's just for our tests. You can drop this library into your projects without dragging along extra baggage.
Features
- Comprehensive list of all recognized countries, provided as a Go slice of structs for easy access and manipulation
- Direct access to raw country and currency JSON data in the data package for custom processing or validation
- Zero
init()overheadโjust import and use thecountriespackage without side effects - Fast, allocation-free lookups for all retrieval functions, ensuring optimal performance in production environments
- Includes region, subregion, capital, and currency information for each country
- Designed for extensibilityโadd or update country data via code generation from JSON sources
- Well-documented, tested, and benchmarked for reliability and speed
Functions
GetAll(): Retrieve the entire slice of all known countries, including metadata such as names, codes, regions, capitals, and currenciesGetByAlpha2(countries.Alpha2US): Find a country by its ISO 3166-1 alpha-2 codeGetByAlpha3(countries.Alpha3USA): Retrieve a country by its ISO 3166-1 alpha-3 codeGetByCapital("Washington"): Find a country by its capital city in a case-insensitive searchGetByCountryCode("840"): Lookup by ISO 3166 numeric country code, supporting string or integer inputGetByISO31662("ISO 3166-2:US"): Retrieve a country by its ISO 3166-2 subdivision codeGetByName("United States of America"): Lookup a country by its official name, supporting case-insensitive queries
Code Generation
If you need to update the country data or regenerate the Go code, you can use the go generate command.
This will read the JSON data files and generate a Go file containing all the country data in a structured format.
To generate the Go code for the country data, follow these steps:
- Navigate to the project root directory:
bash
cd /path/to/your/project
- Run the
go generatecommand:
bash
go generate -x ./generate/...
This command executes the code generation logic defined in the generate.go file located in the /generate/ directory.
The generated code is written to countries_data.go in the project directory.
Additional Documentation & Repository Management
Library Deployment
This project uses [goreleaser](https://github.com/goreleaser/goreleaser) for streamlined binary and library deployment to GitHub. To get started, install it via: ```bash brew install goreleaser ``` The release process is defined in the [.goreleaser.yml](.goreleaser.yml) configuration file. To generate a snapshot (non-versioned) release for testing purposes, run: ```bash make release-snap ``` Before tagging a new version, update the release metadata in the `CITATION.cff` file: ```bash make citation version=0.2.1 ``` Then create and push a new Git tag using: ```bash make tag version=x.y.z ``` This process ensures consistent, repeatable releases with properly versioned artifacts and citation metadata.
Makefile Commands
View all `makefile` commands ```bash script make help ``` List of all current commands: ```text bench ## Run all benchmarks in the Go application build-go ## Build the Go application (locally) citation ## Update version in CITATION.cff (use version=X.Y.Z) clean-mods ## Remove all the Go mod cache coverage ## Show test coverage diff ## Show git diff and fail if uncommitted changes exist fumpt ## Run fumpt to format Go code generate ## Run go generate in the base of the repo godocs ## Trigger GoDocs tag sync govulncheck-install ## Install govulncheck (pass VERSION= to override) govulncheck ## Scan for vulnerabilities help ## Display this help message install-go ## Install using go install with specific version install-releaser ## Install GoReleaser install-stdlib ## Install the Go standard library for the host platform install-template ## Kick-start a fresh copy of go-template (run once!) install ## Install the application binary lint-version ## Show the golangci-lint version lint ## Run the golangci-lint application (install if not found) loc ## Total lines of code table mod-download ## Download Go module dependencies mod-tidy ## Clean up go.mod and go.sum pre-build ## Pre-build all packages to warm cache release-snap ## Build snapshot binaries release-test ## Run release dry-run (no publish) release ## Run production release (requires github_token) tag-remove ## Remove local and remote tag (use version=X.Y.Z) tag-update ## Force-update tag to current commit (use version=X.Y.Z) tag ## Create and push a new tag (use version=X.Y.Z) test-ci-no-race ## CI test suite without race detector test-ci ## CI test runs tests with race detection and coverage (no lint - handled separately) test-cover-race ## Runs unit tests with race detector and outputs coverage test-cover ## Unit tests with coverage (no race) test-fuzz ## Run fuzz tests only (no unit tests) test-no-lint ## Run only tests (no lint) test-parallel ## Run tests in parallel (faster for large repos) test-race ## Unit tests with race detector (no coverage) test-short ## Run tests excluding integration tests (no lint) test ## Default testing uses lint + unit tests (fast) uninstall ## Uninstall the Go binary update-linter ## Upgrade golangci-lint (macOS only) update-releaser ## Reinstall GoReleaser update ## Update dependencies vet-parallel ## Run go vet in parallel (faster for large repos) vet ## Run go vet only on your module packages ```
GitHub Workflows
### ๐๏ธ The Workflow Control Center All GitHub Actions workflows in this repository are powered by a single configuration file: [**.env.shared**](.github/.env.shared) โ your one-stop shop for tweaking CI/CD behavior without touching a single YAML file! ๐ฏ This magical file controls everything from: - **๐ Go version matrix** (test on multiple versions or just one) - **๐ Runner selection** (Ubuntu or macOS, your wallet decides) - **๐ฌ Feature toggles** (coverage, fuzzing, linting, race detection) - **๐ก๏ธ Security tool versions** (gitleaks, nancy, govulncheck) - **๐ค Auto-merge behaviors** (how aggressive should the bots be?) - **๐ท๏ธ PR management rules** (size labels, auto-assignment, welcome messages) > **Pro tip:** Want to disable code coverage? Just flip `ENABLE_CODE_COVERAGE=false` in [.env.shared](.github/.env.shared) and push. No YAML archaeology required!
| Workflow Name | Description | |------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------| | [auto-merge-on-approval.yml](.github/workflows/auto-merge-on-approval.yml) | Automatically merges PRs after approval and all required checks, following strict rules. | | [codeql-analysis.yml](.github/workflows/codeql-analysis.yml) | Analyzes code for security vulnerabilities using [GitHub CodeQL](https://codeql.github.com/). | | [dependabot-auto-merge.yml](.github/workflows/dependabot-auto-merge.yml) | Automatically merges [Dependabot](https://github.com/dependabot) PRs that meet all requirements. | | [fortress.yml](.github/workflows/fortress.yml) | Runs the GoFortress security and testing workflow, including linting, testing, releasing, and vulnerability checks. | | [pull-request-management.yml](.github/workflows/pull-request-management.yml) | Labels PRs by branch prefix, assigns a default user if none is assigned, and welcomes new contributors with a comment. | | [scorecard.yml](.github/workflows/scorecard.yml) | Runs [OpenSSF](https://openssf.org/) Scorecard to assess supply chain security. | | [stale.yml](.github/workflows/stale-check.yml) | Warns about (and optionally closes) inactive issues and PRs on a schedule or manual trigger. | | [sync-labels.yml](.github/workflows/sync-labels.yml) | Keeps GitHub labels in sync with the declarative manifest at [`.github/labels.yml`](./.github/labels.yml). | | [update-python-dependencies.yml](.github/workflows/update-python-dependencies.yml) | Updates Python dependencies for pre-commit hooks in the repository. | | [update-pre-commit-hooks.yml](.github/workflows/update-pre-commit-hooks.yml) | Automatically update versions for [pre-commit](https://pre-commit.com/) hooks |
Updating Dependencies
To update all dependencies (Go modules, linters, and related tools), run: ```bash make update ``` This command ensures all dependencies are brought up to date in a single step, including Go modules and any tools managed by the Makefile. It is the recommended way to keep your development environment and CI in sync with the latest versions.
๐งช Examples & Tests
All unit tests and examples run via GitHub Actions and use Go version 1.24.x. View the configuration file.
Run all tests (fast):
bash script
make test
Run all tests with race detector (slower):
bash script
make test-race
โก Benchmarks
Run the Go benchmarks:
bash script
make bench
Performance benchmarks for the core functions in this library, executed on an Apple M1 Max (ARM64):
| Function | Ops/sec (approx) | Time per op | Allocations | Bytes Allocated |
|------------------------------------|------------------|-------------|-------------|-----------------|
| GetAll | 5,263,413 | 225.4 ns | 1 | 2,048 B |
| GetByAlpha2 | 100,000,000 | 10.36 ns | 0 | 0 B |
| GetByAlpha3 | 100,000,000 | 10.97 ns | 0 | 0 B |
| GetByCapital | 33,426,183 | 35.19 ns | 1 | 16 B |
| GetByCountryCode | 100,467,049 | 11.10 ns | 0 | 0 B |
| GetByISO31662 | 59,682,316 | 20.16 ns | 0 | 0 B |
| GetByName | 46,466,527 | 25.66 ns | 0 | 0 B |
These benchmarks reflect fast, allocation-free lookups for most retrieval functions, ensuring optimal performance in production environments.
๐ ๏ธ Code Standards
Read more about this Go project's code standards.
๐ค AI Compliance
This project documents expectations for AI assistants using a few dedicated files:
- AGENTS.md โ canonical rules for coding style, workflows, and pull requests used by Codex.
- CLAUDE.md โ quick checklist for the Claude agent.
- .cursorrules โ machine-readable subset of the policies for Cursor and similar tools.
- sweep.yaml โ rules for Sweep, a tool for code review and pull request management.
Edit AGENTS.md first when adjusting these policies, and keep the other files in sync within the same pull request.
๐ Credits
Used: ISO-3166-Countries-with-Regional-Codes
Used: List of Countries & Currencies
๐ฅ Maintainers
|
|
|:------------------------------------------------------------------------------------------------:|
| MrZ |
๐ค Contributing
View the contributing guidelines and please follow the code of conduct.
How can I help?
All kinds of contributions are welcome :raisedhands:! The most basic way to show your support is to star :star2: the project, or to raise issues :speechballoon:. You can also support this project by becoming a sponsor on GitHub :clap: or by making a bitcoin donation to ensure this journey continues indefinitely! :rocket:
๐ License
Owner
- Name: Mr. Z
- Login: mrz1836
- Kind: user
- Location: BitCoin
- Company: @skyetel @buxorg @BitcoinSchema @tonicpow @bitcoin-sv
- Website: https://mrz1818.com
- Twitter: mrz1818
- Repositories: 40
- Profile: https://github.com/mrz1836
#DevOps #Go #BitCoin
Citation (CITATION.cff)
cff-version: 1.2.0
message: "If you find go-countries useful in your software or research, please cite this project using the following citation metadata. A citation helps support future development and encourages best practices in software reuse."
title: "go-countries"
version: "1.0.5"
url: "https://github.com/mrz1836/go-countries"
repository: "https://github.com/mrz1836/go-countries"
repository-code: "https://github.com/mrz1836/go-countries"
date-released: 2025-06-04
license: "MIT"
type: software
authors:
- family-names: "Z"
given-names: "Mr"
name: "mrz1836"
keywords:
- golang
- countries
- ISO 3166
- iso-3166
- geographic data
- library
abstract: "A Go library for ISO 3166 country information, including name translations, codes, and metadata for over 250 countries and territories. Useful for applications needing standardized country data in Go projects."
GitHub Events
Total
- Release event: 8
- Watch event: 1
- Delete event: 41
- Issue comment event: 73
- Push event: 132
- Pull request review comment event: 11
- Pull request review event: 65
- Pull request event: 87
- Create event: 48
Last Year
- Release event: 8
- Watch event: 1
- Delete event: 41
- Issue comment event: 73
- Push event: 132
- Pull request review comment event: 11
- Pull request review event: 65
- Pull request event: 87
- Create event: 48
Committers
Last synced: 8 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| mrz1836 | m****8@g****m | 240 |
| dependabot[bot] | 4****] | 66 |
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 0
- Total pull requests: 170
- Average time to close issues: N/A
- Average time to close pull requests: about 3 hours
- Total issue authors: 0
- Total pull request authors: 2
- Average comments per issue: 0
- Average comments per pull request: 0.92
- Merged pull requests: 150
- Bot issues: 0
- Bot pull requests: 91
Past Year
- Issues: 0
- Pull requests: 112
- Average time to close issues: N/A
- Average time to close pull requests: about 3 hours
- Issue authors: 0
- Pull request authors: 2
- Average comments per issue: 0
- Average comments per pull request: 1.05
- Merged pull requests: 94
- Bot issues: 0
- Bot pull requests: 33
Top Authors
Issue Authors
Pull Request Authors
- dependabot[bot] (96)
- mrz1836 (78)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
- Total downloads: unknown
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 24
proxy.golang.org: github.com/mrz1836/go-countries
Package countries is a complete go-ready list of countries in all standardized formats. This package provides functionalities to retrieve country information based on various identifiers such as name, alpha-2 code, alpha-3 code, country code, and ISO 3166-2 code. It includes methods to get a country by these identifiers and to retrieve the entire list of countries. The package is designed to be straightforward to use and integrate into Go projects, making it simple to work with country data in a standardized way. If you have any suggestions or comments, please feel free to open an issue in this GitHub repository! By @MrZ1836 Code generated by go generate; DO NOT EDIT. This file was generated by robots at https://github.com/mrz1836/go-countries
- Homepage: https://github.com/mrz1836/go-countries
- Documentation: https://pkg.go.dev/github.com/mrz1836/go-countries#section-documentation
- License: MIT
-
Latest release: v1.0.5
published 7 months ago
Rankings
Dependencies
- github.com/stretchr/testify v1.8.0
- github.com/davecgh/go-spew v1.1.0
- github.com/davecgh/go-spew v1.1.1
- github.com/pmezard/go-difflib v1.0.0
- github.com/stretchr/objx v0.1.0
- github.com/stretchr/objx v0.4.0
- github.com/stretchr/testify v1.7.1
- github.com/stretchr/testify v1.8.0
- gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405
- gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
- gopkg.in/yaml.v3 v3.0.1
- actions/checkout v3 composite
- github/codeql-action/analyze v2 composite
- github/codeql-action/autobuild v2 composite
- github/codeql-action/init v2 composite
- actions/checkout v3 composite
- actions/setup-go v3 composite
- goreleaser/goreleaser-action v4.2.0 composite
- actions/cache v3 composite
- actions/checkout v3 composite
- actions/setup-go v3 composite
- codecov/codecov-action v3.1.1 composite
- actions/checkout v3 composite
- micnncim/action-label-syncer v1.3.0 composite