AI Decision System
Replayable, offline-verifiable records for AI-assisted go/no-go decisions: experiment promotions, typed model answers and human-approved actions.
翻譯準備中
尚未偵測到更新。GitHub 發布版本後會顯示在這裡。
個人 GitHub 帳號下公開儲存庫的擁有者可以登入並驗證所有權,自行管理介紹,無需管理員核准。
登入並產生驗證檔案,在 30 分鐘內將其提交至此儲存庫的預設分支。其他分支或分叉儲存庫中的檔案無效。然後在下方檢查檔案,即可無需管理員核准直接管理專案。請保留檔案以維持管理權限。
如需登入,將前往登入頁面。登入後請回到此處,再次點擊所選的驗證按鈕。
在專案資料夾中執行 /nomorevibe verify,即可驗證所有權並自行管理介紹。
一分鐘完成驗證正在載入完整 README。 以下為已儲存的摘錄。
A Go-based REST API for geocoding location lookup using US ZIP codes and Ohio address data, built with Echo framework and PostgreSQL with PostGIS. • 🏃 Fast geocoding lookup by ZIP code • 🔍 Search ZIP codes by city name and state • 🏠 Ohio address data from official state sources • 🗺️ Shapefile to GeoJSON conversion using GDAL • 🗄️ PostgreSQL database with PostGIS for geospatial queries • 🚀 Built with Echo web framework • 🐳 Docker support with Docker Compose • 📊 Comprehensive location data including population, density, coordinates, and county information檢視完整 README ↗
A Go-based REST API for geocoding location lookup using US ZIP codes and Ohio address data, built with Echo framework and PostgreSQL with PostGIS.
timezone_source, and GET /api/v1/admin/boundaries
reports which release is loaded.brew install gdalsudo apt-get install gdal-bin# Run the setup script
./scripts/setup_dev.sh
This will:
Install GDAL (optional but recommended)
# macOS
brew install gdal
# Ubuntu/Debian
sudo apt-get install gdal-bin
Start Docker services
docker compose up -d db pgadmin
Install Go dependencies
go mod download
Run the application
go run main.go
# or with hot reloading
air
# Start API with docs
make dev
# Visit documentation
open http://localhost:8080/docs
# Or serve docs only
make docs
GET /api/v1/geocode/{zipcode}
Returns detailed information for a specific ZIP code.
Example:
curl http://localhost:8080/api/v1/geocode/10001
Response:
{
"success": true,
"data": {
"zip_code": "10001",
"city_name": "New York",
"state_code": "NY",
"state_name": "New York",
"zcta": true,
"population": 21102.0,
"density": 35400.5,
"primary_county_code": "36061",
"primary_county_name": "New York",
"county_weights": {"36061": "100"},
"county_names": ["New York"],
"county_codes": ["36061"],
"imprecise": false,
"military": false,
"timezone": "America/New_York",
"latitude": 40.75066,
"longitude": -73.99670
},
"count": 1
}
GET /api/v1/search?city={city_name}&state={state_code}&limit={limit}
Search for ZIP codes by city name, optionally filtered by state.
Parameters:
city (required): City name to search forstate (optional): Two-letter state code (e.g., "NY", "CA")limit (optional): Maximum number of results (default: 50, max: 100)Example:
curl "http://localhost:8080/api/v1/search?city=Springfield&state=IL&limit=10"
GET /api/v1/distance/{from}/{to}
Calculate the precise distance between two ZIP codes using the Haversine formula.
Example:
curl http://localhost:8080/api/v1/distance/10001/90210
Response:
{
"success": true,
"data": {
"from_zip_code": "10001",
"to_zip_code": "90210",
"distance_miles": 2445.5,
"distance_km": 3936.2
},
"count": 1
}
GET /api/v1/nearby/{zipcode}?radius={miles}&limit={limit}
Find all ZIP codes within a specified radius of a center ZIP code.
Parameters:
radius (optional): Search radius in miles (default: 1, max: 100)limit (optional): Maximum results (default: 50, max: 200)Example:
curl "http://localhost:8080/api/v1/nearby/10001?radius=5&limit=10"
GET /api/v1/proximity/{center}/{target}?radius={miles}
Check if a target ZIP code is within a specified radius of a center ZIP code.
Example:
curl "http://localhost:8080/api/v1/proximity/10001/10002?radius=1"
Response:
{
"success": true,
"data": {
"center_zip_code": "10001",
"target_zip_code": "10002",
"radius_miles": 1,
"is_within_radius": true,
"actual_distance_miles": 0.5,
"actual_distance_km": 0.8
},
"count": 1
}
GET /api/v1/health
Returns the API health status.
POST /api/v1/admin/load-data?file={csv_file_path}
Loads ZIP code data from CSV file into the database.
Clone or set up the project:
git clone <your-repo-url>
cd geocoding-api
Ensure the CSV file is present:
Make sure georef-united-states-of-america-zc-point.csv is in the project root.
Start the services:
docker-compose up -d
Load the ZIP code data:
curl -X POST http://localhost:8080/api/v1/admin/load-data
Test the API:
curl http://localhost:8080/api/v1/geocode/10001
Install dependencies:
go mod download
Set up PostgreSQL database:
CREATE DATABASE geocoding_db;
Configure environment variables:
cp .env.example .env
# Edit .env with your database configuration
Run the application:
go run main.go
Load the ZIP code data:
curl -X POST http://localhost:8080/api/v1/admin/load-data
| Variable | Description | Default |
|---|---|---|
DB_HOST | PostgreSQL host | localhost |
DB_PORT | PostgreSQL port | 5432 |
DB_USER | PostgreSQL username | postgres |
DB_PASSWORD | PostgreSQL password | postgres |
DB_NAME | PostgreSQL database name | geocoding_db |
DB_SSLMODE | PostgreSQL SSL mode | disable |
PORT | API server port | 8080 |
The ZIP code data includes the following fields:
CREATE TABLE zip_codes (
zip_code VARCHAR(10) PRIMARY KEY,
city_name VARCHAR(255) NOT NULL,
state_code VARCHAR(2) NOT NULL,
state_name VARCHAR(255) NOT NULL,
zcta BOOLEAN NOT NULL DEFAULT FALSE,
zcta_parent VARCHAR(10),
population DECIMAL(12,2),
density DECIMAL(10,2),
primary_county_code VARCHAR(10) NOT NULL,
primary_county_name VARCHAR(255) NOT NULL,
county_weights JSONB,
county_names TEXT,
county_codes TEXT,
imprecise BOOLEAN NOT NULL DEFAULT FALSE,
military BOOLEAN NOT NULL DEFAULT FALSE,
timezone VARCHAR(100) NOT NULL,
latitude DECIMAL(10,7) NOT NULL,
longitude DECIMAL(10,7) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
This project uses a custom migration system with version tracking. Migrations run automatically when the application starts.
The application automatically:
schema_migrations table to track applied migrationsMigration files are located in:
database/migrations.go - Migration definitionsservices/zipcode_service.go - Data loading logicThe application automatically downloads address data from the Ohio LBRS site for all 88 Ohio counties.
Data Flow:
ADA_ADDS.zip)Requirements:
Testing:
# Test GDAL installation and conversion
./scripts/test_gdal.sh
# This will download and convert a sample county
Manual trigger:
# Force re-download and conversion
# Delete cached files and restart the application
rm -rf oh/* cache/*
go run main.go
For more advanced migration needs, you can use golang-migrate:
# Install migrate tool
make install-tools
# Create a new migration
make migrate-create
# Apply migrations
make migrate-up
# Rollback migrations
make migrate-down
# Check migration status
make migrate-version
Migration files: migrations/*.sql
The application automatically loads ZIP code data on first run:
curl -X POST http://localhost:8080/api/v1/admin/load-datamake load-dataThe production Docker image automatically optimizes its size by:
ENV=production) or when explicitly enabled (CLEANUP_GEOJSON=true)For optimal production deployment, set these environment variables:
ENV=production # Enables production optimizations
CLEANUP_GEOJSON=true # Forces GeoJSON cleanup regardless of ENV
In development, GeoJSON files are preserved by default. To test cleanup locally:
CLEANUP_GEOJSON=true docker-compose up
The database includes several indexes for optimal query performance:
zip_codestate_code for state-based filteringcity_name for city searcheslatitude, longitude for geographical queriesThe API returns standardized error responses:
{
"success": false,
"error": "Error description"
}
Common HTTP status codes:
200: Success400: Bad Request (invalid parameters)404: Not Found (ZIP code not found)500: Internal Server ErrorThis project is licensed under the MIT License - see the LICENSE file for details.
This API uses ZIP code data from the GeoNames geographical database. The data includes comprehensive information about US ZIP codes including geographical coordinates, administrative boundaries, and demographic information.