A lightweight, production-ready Golang HTTP backend for managing delivery location hubs.
It supports full CRUD operations on hubs with polygon boundaries, real-time location validation (point-in-polygon), and automatic convex hull computation for optimal delivery zone boundaries — all backed by SQLite.
Built with clean architecture (Gin + GORM) and optimized for delivery management systems.
- Full CRUD for Delivery Hubs (single or multiple polygons per hub)
- Location Checking – POST
/check-locationsreturns whether each point falls inside any hub’s polygon(s) - Convex Hull Endpoint – POST
/boundary-polygoncomputes the minimal enclosing polygon using Andrew’s Monotone Chain - Bearer Token Authentication (simple
secret-tokenfor demo/production) - SQLite Persistence with automatic migrations
- Health Check endpoint
- Input Validation & meaningful error messages
- GeoJSON-ready polygons (closed, counter-clockwise)
- Handles edge cases: collinear points, degenerate hulls, boundary points
- Language: Go (1.21+)
- Framework: Gin
- ORM / DB: GORM + SQLite
- Convex Hull: Andrew’s Monotone Chain (O(n log n))
- Point-in-Polygon: Ray Casting (Jordan curve) with boundary support
- Testing:
testing+httptest
git clone <your-repo>
cd delivery-hubs-service
go mod tidygo run main.go --command startServer starts at http://localhost:8080
curl -X GET http://localhost:8080/healthAll endpoints except /health require:
-H "Authorization: Bearer secret-token"POST– Create hub (single or multi-polygon)GET– List all or filter by?business_id=xxxGET /:id– Get single hubPUT /:id– Partial updateDELETE /:id– Delete hub
Detailed docs: delivery-hubs-api-tests.md
Check multiple delivery points against all hubs for a business.
Returns found: true/false + full hub data when inside.
Detailed docs: check-locations.md
Computes the minimal convex hull from any set of coordinates.
Perfect for generating optimized delivery zones.
Detailed docs: boundary-polygon.md
delivery-hubs-service/
├── main.go
├── internal/
│ ├── models/
│ ├── repository/
│ ├── service/
│ ├── handler/
│ └── middleware/
├── docs/
│ ├── delivery-hubs-api-tests.md
│ ├── check-locations.md
│ └── boundary-polygon.md
└── go.mod
Run the complete test flows provided in the documentation files:
- Health check
- Create → List → Get → Update → Delete hubs
- Check locations (inside/outside)
- Boundary polygon (normal + degenerate cases)
All curl examples are ready to copy-paste.
- Polygons must be closed (first = last coordinate)
- Minimum 3 points per polygon
- Collinear points are automatically filtered in convex hull
- The service is designed to work with the convex hull + convex-optimized PIP combination for maximum performance
- Add PostgreSQL support
- GeoJSON response format
- Multi-tenant business isolation
- Rate limiting & JWT auth
- Docker & Kubernetes manifests
MIT – feel free to use, modify, and deploy in production.
Made for delivery optimization
Questions or contributions? Open an issue or PR!
Happy delivering! 🚀