
π go-cloud-k8s-thing
A modern Proto-first microservice for managing "Things" β built with Go, gRPC, ConnectRPC, and designed for cloud-native Kubernetes deployments.
Proto as Source of Truth: API contracts are defined in Protocol Buffers, generating both Go code and OpenAPI specs automatically. Clients can connect via REST, gRPC, or Connect protocols.
β¨ Features
- π JWT Authentication β Secure endpoints with token-based auth from go-cloud-k8s-user-group
- π‘ Multi-Protocol Support β REST, gRPC, and Connect (JSON/Proto) via Vanguard transcoding
- π Proto-First Design β Single source of truth for API definitions
- π PostgreSQL Backend β Robust data persistence with pgx driver
- π³ Container Ready β Optimized Docker images with CVE scanning via Trivy
- βΈοΈ Kubernetes Native β Ready for K8s deployment with health checks and metrics
ποΈ Architecture
graph TB
subgraph Clients["π± Clients"]
REST["π REST<br/>GET /goapi/v1/thing"]
CONNECT["β‘ Connect<br/>JSON / Proto"]
GRPC["π gRPC"]
end
subgraph Server["π₯οΈ Echo Server"]
VG["π Vanguard Transcoder"]
subgraph Services["Connect Services"]
TS["ThingService"]
TTS["TypeThingService"]
end
end
subgraph Core["βοΈ Business Layer"]
BS["BusinessService"]
ST["Storage Interface"]
end
subgraph Data["πΎ Data Layer"]
PG[(PostgreSQL)]
end
REST --> VG
CONNECT --> VG
GRPC --> VG
VG --> TS
VG --> TTS
TS --> BS
TTS --> BS
BS --> ST
ST --> PG
π¦ Proto-First API Design
The API is defined using Protocol Buffers as the single source of truth:
api/proto/thing/v1/
βββ thing.proto # ThingService definitions
βββ type_thing.proto # TypeThingService definitions
Generated Artifacts
| Source |
Generated |
Purpose |
.proto files |
gen/thing/v1/*.go |
Go types & gRPC stubs |
.proto files |
gen/thing/v1/thingv1connect/*.go |
Connect handlers |
.proto files |
api/openapi/thing.yaml |
OpenAPI 3.0 spec |
Regenerate Code
./scripts/buf_generate.sh
# or
buf generate api/proto
π API Endpoints
All endpoints are prefixed with /goapi/v1 and require JWT authentication.
Thing Resources
| Method |
Endpoint |
Description |
GET |
/goapi/v1/thing |
List things |
POST |
/goapi/v1/thing |
Create a thing |
GET |
/goapi/v1/thing/{id} |
Get thing by ID |
PUT |
/goapi/v1/thing/{id} |
Update a thing |
DELETE |
/goapi/v1/thing/{id} |
Delete a thing |
GET |
/goapi/v1/thing/search |
Search things |
GET |
/goapi/v1/thing/count |
Count things |
GET |
/goapi/v1/thing/geojson |
Get GeoJSON |
TypeThing Resources
| Method |
Endpoint |
Description |
GET |
/goapi/v1/types |
List type things |
POST |
/goapi/v1/types |
Create type thing |
GET |
/goapi/v1/types/{id} |
Get type thing by ID |
PUT |
/goapi/v1/types/{id} |
Update type thing |
DELETE |
/goapi/v1/types/{id} |
Delete type thing |
GET |
/goapi/v1/types/count |
Count type things |
Connect RPC Endpoints
# Connect JSON format
curl -X POST http://localhost:9090/thing.v1.ThingService/List \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{"limit": 10}'
π Quick Start
Prerequisites
- Go 1.21+
- PostgreSQL 14+
- buf (for proto generation)
Environment Variables
# Required
export PORT=9090
export DB_HOST=localhost
export DB_PORT=5432
export DB_NAME=go_cloud_k8s_thing
export DB_USER=your_user
export DB_PASSWORD=your_password
export JWT_SECRET=your_jwt_secret
export ADMIN_PASSWORD=your_admin_password
Run Locally
# Install dependencies
go mod download
# Run database migrations
# (migrations are auto-applied on startup)
# Start the server
go run ./cmd/goCloudK8sThingServer
Run Tests
make test
π³ Docker
Pull from GitHub Container Registry
docker pull ghcr.io/lao-tseu-is-alive/go-cloud-k8s-thing:latest
Build Locally
docker build -t go-cloud-k8s-thing .
Find all available versions in the Packages section.
π Documentation
π οΈ Tech Stack
| Category |
Technology |
| Language |
Go 1.21+ |
| API Framework |
Echo |
| RPC |
ConnectRPC + Vanguard |
| Proto Tooling |
buf |
| Database |
PostgreSQL with pgx |
| Auth |
JWT via cristalhq/jwt |
| Monitoring |
Prometheus metrics |
| Container |
Docker with multi-stage builds |
| Security |
Trivy CVE scanning |
π Project Structure
go-cloud-k8s-thing/
βββ api/
β βββ proto/thing/v1/ # π Proto definitions (source of truth)
β βββ openapi/ # π Generated OpenAPI specs
βββ cmd/
β βββ goCloudK8sThingServer/ # π Main application entry point
βββ gen/
β βββ thing/v1/ # βοΈ Generated Go code from protos
βββ pkg/
β βββ thing/ # π¦ Business logic
β βββ business_service.go # Core business operations
β βββ connect_server.go # Connect RPC handlers
β βββ mappers.go # Domain β Proto conversion
β βββ storage_postgres.go # Database operations
βββ db/migrations/ # ποΈ SQL migrations
βββ scripts/ # π§ Build & generation scripts
βββ documentation/ # π Requirements & docs
π Security
- All CVE scans performed automatically before container builds
- JWT authentication required for all
/goapi/v1/* endpoints
- SonarCloud analysis for code quality and security
- Dependabot for dependency updates
π License
MIT License β See LICENSE for details.
Built with β€οΈ using Go, Proto, and Connect