Production-ready API Gateway. Gin + NATS integration. Role-based auth. Minimal footprint.
352
High-performance API Gateway built with Go and Gin framework. Provides centralized HTTP entry point for NATS-based microservices with authentication, routing, and service orchestration.
docker run -d \
--name gateway \
-p 3000:3000 \
-e NATS_URL=nats://your-nats-server:4222 \
-e ENV=production \
-e DOMAIN=yourdomain.com \
carfdev/carfdev-gateway:latest
linux/amd64 and linux/arm64| Variable | Description | Required | Default |
|---|---|---|---|
PORT | HTTP server port | No | 8080 |
GIN_MODE | Gin mode (debug/release) | No | debug |
ENV | Environment (development/production) | No | development |
DOMAIN | Domain for cookies | No | localhost:8080 |
NATS_URL | NATS server URL | No | nats://localhost:4222 |
/v1/email/send-contactSend contact form submissions to email service via NATS.
Request:
{
"firstName": "John",
"lastName": "Doe",
"email": "[email protected]",
"companyName": "Acme Corp",
"projectType": "new-website",
"budget": "50k-100k",
"message": "We need help with..."
}
Response:
{
"status": 200,
"data": {
"message": "Contact email sent successfully"
},
"timestamp": 1699632000
}
Project Types: new-website, e-commerce, redesign, web-app, optimization, other
Budget Options: under-50k, 50k-100k, 100k-200k, 200k-plus
Protected routes use Bearer token authentication:
curl -X GET https://api.yourdomain.com/v1/protected \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
The middleware validates tokens via NATS (users.check_access subject) and supports role-based access control.
version: '3.8'
services:
nats:
image: nats:latest
ports:
- "4222:4222"
emailsvc:
image: carfdev/carfdev-emailsvc:latest
environment:
- NATS_URL=nats://nats:4222
- EMAIL_KEY=${RESEND_API_KEY}
depends_on:
- nats
gateway:
image: carfdev/carfdev-gateway:latest
ports:
- "3000:3000"
environment:
- PORT=3000
- NATS_URL=nats://nats:4222
- ENV=production
- DOMAIN=yourdomain.com
- GIN_MODE=release
depends_on:
- nats
- emailsvc
restart: unless-stopped
apiVersion: apps/v1
kind: Deployment
metadata:
name: gateway
spec:
replicas: 3
selector:
matchLabels:
app: gateway
template:
metadata:
labels:
app: gateway
spec:
containers:
- name: gateway
image: carfdev/carfdev-gateway:latest
ports:
- containerPort: 8080
env:
- name: PORT
value: "8080"
- name: NATS_URL
value: "nats://nats-service:4222"
- name: ENV
value: "production"
- name: GIN_MODE
value: "release"
resources:
requests:
memory: "32Mi"
cpu: "100m"
limits:
memory: "128Mi"
cpu: "500m"
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 10
periodSeconds: 30
---
apiVersion: v1
kind: Service
metadata:
name: gateway
spec:
selector:
app: gateway
ports:
- port: 80
targetPort: 8080
type: LoadBalancer
The gateway communicates with microservices via NATS subjects:
email.send_contact - Forward contact form to email serviceusers.check_access - Validate authentication tokensEnvelope Format:
{
"data": { ... },
"error": {
"code": "ERROR_CODE",
"message": "Error description"
}
}
βββββββββββββββ ββββββββββββ βββββββββββββββ
β Clients βββHTTPββββ Gateway βββNATSββββMicroservicesβ
β (Web/Mobile)β β (REST) β β (Email, β
βββββββββββββββ ββββββββββββ β Users) β
βββββββββββββββ
The gateway is stateless and scales horizontally:
# Scale to 5 replicas
kubectl scale deployment gateway --replicas=5
# Or with Docker Compose
docker-compose up --scale gateway=5
MIT License - see repository for details
carfdev - Building cloud-native microservices
Tags: api-gateway, microservices, nats, golang, gin, rest-api, docker, kubernetes, cloud-native
Content type
Image
Digest
sha256:0a0bcfebeβ¦
Size
14.7 MB
Last updated
12 months ago
docker pull carfdev/carfdev-gateway