Return a list of zip codes within a search radius of another zip code.
- Go 92.2%
- Dockerfile 7.8%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .env.example | ||
| .gitignore | ||
| compose.yml | ||
| conv.go | ||
| db.go | ||
| Dockerfile | ||
| go.mod | ||
| go.sum | ||
| handler.go | ||
| main.go | ||
| middleware.go | ||
| README.md | ||
Introduction
zipcode_search is a very simple application (bootstrapped via prompt to DeepSeek v4 Pro 0813).
It provides an alternative implementation modeled after the '/radius' enpoint of the API documented at: https://app.zipcodebase.com/documentation
For example:
https://{your domain}/api/v1/radius?apikey=YOUR-APIKEY&code=02134&radius=1&country=us
Note the following potential differences:
- country is ignored
- only a single source zipcode may be specified
- unit is supported (km|mi), default mi
- apikey is supported as a query string, but if provided in a header (
X-API-Key) it will be preferred.
Example usage
$ go mod download
$ export API_KEY=secret DUCKDB_PATH=zipsearch.duckdb
$ go run .
$ # Query within 10 miles:
$ curl -H "X-API-Key: secret" \
"http://localhost:8080/api/v1/radius?code=10001&radius=10&unit=mi"
Database sources
https://www.nber.org/research/data/zip-code-distance-database
Using duckdb cli, you can load the database as follows (using the 50 mile db):
$ duckdb zipsearch.duckdb
zipsearch D create table zip_distance (zip1 varchar, zip2 varchar, distance float);
zipsearch D insert into zip_distance (zip1, zip2, distance) select zip1, zip2, miles_to_zcta5 from 'gaz2024zcta5distance50miles.csv';
zipsearch D .exit