Initial commit: Go DNS microservice boilerplate

This commit is contained in:
Aiden Smith
2026-02-24 13:44:34 -05:00
commit 247f81d616
13 changed files with 451 additions and 0 deletions

61
README.md Normal file
View File

@@ -0,0 +1,61 @@
# VectorDNS Go Server
A lightweight Go DNS lookup microservice powered by Chi and miekg/dns.
## Quick Start
```bash
# Copy env config
cp .env.example .env
# Install dependencies
go mod tidy
# Run the server
go run ./cmd/server
```
The server starts on `http://localhost:8080`.
## Endpoints
| Method | Path | Description |
|--------|------|-------------|
| GET | `/healthz` | Health check |
| POST | `/api/v1/dns/lookup` | DNS record lookup |
### DNS Lookup
```bash
curl -X POST http://localhost:8080/api/v1/dns/lookup \
-H "Content-Type: application/json" \
-d '{"domain": "example.com", "types": ["A", "MX"]}'
```
If `types` is omitted, all 9 record types are queried (A, AAAA, MX, TXT, NS, CNAME, SOA, CAA, SRV).
## Configuration
All config is via environment variables (or `.env` file):
| Variable | Default | Description |
|----------|---------|-------------|
| `PORT` | `8080` | Server port |
| `API_KEY` | (empty) | API key for auth (disabled if empty) |
| `CORS_ORIGINS` | `http://localhost:3000` | Comma-separated allowed origins |
| `LOG_FORMAT` | `text` | `text` or `json` |
## Docker
```bash
docker build -t vectordns-server .
docker run -p 8080:8080 --env-file .env vectordns-server
```
## Tech Stack
- **Router**: [Chi v5](https://github.com/go-chi/chi)
- **DNS**: [miekg/dns](https://github.com/miekg/dns)
- **Logging**: stdlib `log/slog`
- **Rate Limiting**: [go-chi/httprate](https://github.com/go-chi/httprate)
- **CORS**: [go-chi/cors](https://github.com/go-chi/cors)