@mytechtoday/augment-extensions 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/augment-extensions/coding-standards/c/CHANGELOG.md +55 -0
- package/augment-extensions/coding-standards/c/LICENSE +22 -0
- package/augment-extensions/coding-standards/c/README.md +167 -0
- package/augment-extensions/coding-standards/c/config/defaults.json +26 -0
- package/augment-extensions/coding-standards/c/config/examples/embedded.yaml +25 -0
- package/augment-extensions/coding-standards/c/config/examples/systems.json +31 -0
- package/augment-extensions/coding-standards/c/config/schema.json +244 -0
- package/augment-extensions/coding-standards/c/docs/API.md +613 -0
- package/augment-extensions/coding-standards/c/docs/CONFIGURATION.md +259 -0
- package/augment-extensions/coding-standards/c/docs/USER_GUIDE.md +567 -0
- package/augment-extensions/coding-standards/c/examples/drivers/Makefile +33 -0
- package/augment-extensions/coding-standards/c/examples/drivers/README.md +192 -0
- package/augment-extensions/coding-standards/c/examples/drivers/dma-example.c +224 -0
- package/augment-extensions/coding-standards/c/examples/drivers/example.dts +64 -0
- package/augment-extensions/coding-standards/c/examples/drivers/platform-driver.c +174 -0
- package/augment-extensions/coding-standards/c/examples/embedded/README.md +167 -0
- package/augment-extensions/coding-standards/c/examples/embedded/gpio-control.c +172 -0
- package/augment-extensions/coding-standards/c/examples/embedded/timer-isr.c +198 -0
- package/augment-extensions/coding-standards/c/examples/embedded/uart-communication.c +212 -0
- package/augment-extensions/coding-standards/c/examples/kernel/Makefile +82 -0
- package/augment-extensions/coding-standards/c/examples/kernel/README.md +168 -0
- package/augment-extensions/coding-standards/c/examples/kernel/char-device.c +198 -0
- package/augment-extensions/coding-standards/c/examples/kernel/proc-file.c +131 -0
- package/augment-extensions/coding-standards/c/examples/kernel/simple-module.c +111 -0
- package/augment-extensions/coding-standards/c/examples/legacy/Makefile +62 -0
- package/augment-extensions/coding-standards/c/examples/legacy/README.md +255 -0
- package/augment-extensions/coding-standards/c/examples/legacy/c89-to-c11-migration.c +268 -0
- package/augment-extensions/coding-standards/c/examples/legacy/compatibility-layer.c +239 -0
- package/augment-extensions/coding-standards/c/examples/networking/Makefile +35 -0
- package/augment-extensions/coding-standards/c/examples/networking/README.md +207 -0
- package/augment-extensions/coding-standards/c/examples/networking/protocol-parser.c +270 -0
- package/augment-extensions/coding-standards/c/examples/networking/tcp-server.c +197 -0
- package/augment-extensions/coding-standards/c/examples/networking/udp-multicast.c +220 -0
- package/augment-extensions/coding-standards/c/examples/realtime/Makefile +53 -0
- package/augment-extensions/coding-standards/c/examples/realtime/README.md +199 -0
- package/augment-extensions/coding-standards/c/examples/realtime/deadline-monitoring.c +260 -0
- package/augment-extensions/coding-standards/c/examples/realtime/priority-scheduling.c +258 -0
- package/augment-extensions/coding-standards/c/examples/systems/Makefile +34 -0
- package/augment-extensions/coding-standards/c/examples/systems/README.md +123 -0
- package/augment-extensions/coding-standards/c/examples/systems/ipc-pipes.c +181 -0
- package/augment-extensions/coding-standards/c/examples/systems/process-management.c +153 -0
- package/augment-extensions/coding-standards/c/examples/systems/signal-handling.c +162 -0
- package/augment-extensions/coding-standards/c/module.json +149 -0
- package/augment-extensions/coding-standards/c/rules/categories/drivers.md +635 -0
- package/augment-extensions/coding-standards/c/rules/categories/embedded.md +510 -0
- package/augment-extensions/coding-standards/c/rules/categories/kernel.md +653 -0
- package/augment-extensions/coding-standards/c/rules/categories/legacy.md +526 -0
- package/augment-extensions/coding-standards/c/rules/categories/networking.md +735 -0
- package/augment-extensions/coding-standards/c/rules/categories/realtime.md +631 -0
- package/augment-extensions/coding-standards/c/rules/categories/systems.md +586 -0
- package/augment-extensions/coding-standards/c/rules/universal/const-correctness.md +275 -0
- package/augment-extensions/coding-standards/c/rules/universal/documentation.md +251 -0
- package/augment-extensions/coding-standards/c/rules/universal/error-handling.md +250 -0
- package/augment-extensions/coding-standards/c/rules/universal/header-guards.md +254 -0
- package/augment-extensions/coding-standards/c/rules/universal/memory-safety.md +233 -0
- package/augment-extensions/coding-standards/c/rules/universal/naming.md +146 -0
- package/augment-extensions/coding-standards/c/src/conflict-detector.ts +461 -0
- package/augment-extensions/coding-standards/c/src/prompt-generator.ts +307 -0
- package/augment-extensions/coding-standards/c/src/rule-evaluator.ts +307 -0
- package/augment-extensions/coding-standards/c/src/rule-override.ts +427 -0
- package/augment-extensions/coding-standards/c/src/template-engine.ts +217 -0
- package/augment-extensions/coding-standards/c/templates/prompts/drivers.txt +191 -0
- package/augment-extensions/coding-standards/c/templates/prompts/embedded.txt +164 -0
- package/augment-extensions/coding-standards/c/templates/prompts/kernel.txt +175 -0
- package/augment-extensions/coding-standards/c/templates/prompts/legacy.txt +280 -0
- package/augment-extensions/coding-standards/c/templates/prompts/networking.txt +259 -0
- package/augment-extensions/coding-standards/c/templates/prompts/realtime.txt +219 -0
- package/augment-extensions/coding-standards/c/templates/prompts/systems.txt +147 -0
- package/augment-extensions/coding-standards/c/tests/integration/category-specific.test.ts +356 -0
- package/augment-extensions/coding-standards/c/tests/integration/end-to-end-workflow.test.ts +377 -0
- package/augment-extensions/coding-standards/c/tests/performance/benchmarks.test.ts +407 -0
- package/augment-extensions/coding-standards/c/tests/unit/config-manager.test.ts +345 -0
- package/augment-extensions/coding-standards/c/tests/unit/conflict-detector.test.ts +294 -0
- package/augment-extensions/coding-standards/c/tests/unit/prompt-generator.test.ts +174 -0
- package/augment-extensions/coding-standards/c/tests/unit/registry.test.ts +313 -0
- package/augment-extensions/coding-standards/c/tests/unit/rule-evaluator.test.ts +318 -0
- package/augment-extensions/coding-standards/c/tests/unit/rule-override.test.ts +326 -0
- package/augment-extensions/coding-standards/c/tests/unit/template-engine.test.ts +314 -0
- package/augment-extensions/coding-standards/go/CHARACTER-COUNT-REPORT.md +135 -0
- package/augment-extensions/coding-standards/go/PHASE1-COMPLETION.md +146 -0
- package/augment-extensions/coding-standards/go/PHASE4-COMPLETION.md +184 -0
- package/augment-extensions/coding-standards/go/README.md +200 -0
- package/augment-extensions/coding-standards/go/VALIDATION-CHECKLIST.md +154 -0
- package/augment-extensions/coding-standards/go/config/examples/example-cli.json +15 -0
- package/augment-extensions/coding-standards/go/config/examples/example-microservices.json +21 -0
- package/augment-extensions/coding-standards/go/config/examples/example-multi-category.yaml +24 -0
- package/augment-extensions/coding-standards/go/config/examples/example-web.json +15 -0
- package/augment-extensions/coding-standards/go/config/schema.json +110 -0
- package/augment-extensions/coding-standards/go/docs/CATEGORIES.md +221 -0
- package/augment-extensions/coding-standards/go/docs/CONFIGURATION.md +198 -0
- package/augment-extensions/coding-standards/go/docs/TROUBLESHOOTING.md +285 -0
- package/augment-extensions/coding-standards/go/examples/cli/cobra-app.go +287 -0
- package/augment-extensions/coding-standards/go/examples/cloud-native-app.go +217 -0
- package/augment-extensions/coding-standards/go/examples/devops-tool.go +250 -0
- package/augment-extensions/coding-standards/go/examples/distributed-system.go +247 -0
- package/augment-extensions/coding-standards/go/examples/microservices/grpc-service.go +253 -0
- package/augment-extensions/coding-standards/go/examples/rest-api.go +270 -0
- package/augment-extensions/coding-standards/go/examples/web/http-server.go +224 -0
- package/augment-extensions/coding-standards/go/module.json +139 -0
- package/augment-extensions/coding-standards/go/rules/categories/api-development/api-versioning.md +149 -0
- package/augment-extensions/coding-standards/go/rules/categories/api-development/rate-limiting.md +209 -0
- package/augment-extensions/coding-standards/go/rules/categories/api-development/rest-api-design.md +183 -0
- package/augment-extensions/coding-standards/go/rules/categories/cloud-native/cloud-config.md +193 -0
- package/augment-extensions/coding-standards/go/rules/categories/cloud-native/health-checks.md +231 -0
- package/augment-extensions/coding-standards/go/rules/categories/cloud-native/kubernetes.md +180 -0
- package/augment-extensions/coding-standards/go/rules/categories/devops-tooling/automation.md +179 -0
- package/augment-extensions/coding-standards/go/rules/categories/devops-tooling/ci-cd-integration.md +147 -0
- package/augment-extensions/coding-standards/go/rules/categories/devops-tooling/infrastructure-as-code.md +231 -0
- package/augment-extensions/coding-standards/go/rules/categories/distributed-systems/caching.md +150 -0
- package/augment-extensions/coding-standards/go/rules/categories/distributed-systems/consensus.md +187 -0
- package/augment-extensions/coding-standards/go/rules/categories/distributed-systems/event-sourcing.md +246 -0
- package/augment-extensions/coding-standards/go/rules/cli/command-parsing.md +264 -0
- package/augment-extensions/coding-standards/go/rules/cli/configuration.md +268 -0
- package/augment-extensions/coding-standards/go/rules/cli/cross-platform.md +324 -0
- package/augment-extensions/coding-standards/go/rules/microservices/distributed-tracing.md +253 -0
- package/augment-extensions/coding-standards/go/rules/microservices/grpc.md +257 -0
- package/augment-extensions/coding-standards/go/rules/microservices/metrics.md +278 -0
- package/augment-extensions/coding-standards/go/rules/microservices/service-discovery.md +249 -0
- package/augment-extensions/coding-standards/go/rules/universal/code-organization.md +221 -0
- package/augment-extensions/coding-standards/go/rules/universal/documentation.md +269 -0
- package/augment-extensions/coding-standards/go/rules/universal/performance.md +323 -0
- package/augment-extensions/coding-standards/go/rules/universal/testing.md +162 -0
- package/augment-extensions/coding-standards/go/rules/web/graceful-shutdown.md +249 -0
- package/augment-extensions/coding-standards/go/rules/web/http-handlers.md +164 -0
- package/augment-extensions/coding-standards/go/rules/web/middleware.md +234 -0
- package/augment-extensions/coding-standards/go/rules/web/routing.md +251 -0
- package/augment-extensions/coding-standards/go/templates/prompts/api.md +160 -0
- package/augment-extensions/coding-standards/go/templates/prompts/cli.md +225 -0
- package/augment-extensions/coding-standards/go/templates/prompts/cloud-native.md +121 -0
- package/augment-extensions/coding-standards/go/templates/prompts/devops.md +146 -0
- package/augment-extensions/coding-standards/go/templates/prompts/distributed.md +133 -0
- package/augment-extensions/coding-standards/go/templates/prompts/microservices.md +225 -0
- package/augment-extensions/coding-standards/go/templates/prompts/web.md +181 -0
- package/augment-extensions/coding-standards/go/tests/integration/module-integration.test.ts +164 -0
- package/augment-extensions/coding-standards/go/tests/unit/category-selection.test.ts +147 -0
- package/augment-extensions/coding-standards/go/tests/unit/module-structure.test.ts +154 -0
- package/augment-extensions/coding-standards/go/tests/validate-character-count.ps1 +13 -0
- package/augment-extensions/coding-standards/go/tests/validate-examples.ps1 +148 -0
- package/augment-extensions/coding-standards/go/tests/validate-examples.sh +135 -0
- package/cli/dist/analysis/ast-parser.d.ts +47 -0
- package/cli/dist/analysis/ast-parser.d.ts.map +1 -0
- package/cli/dist/analysis/ast-parser.js +161 -0
- package/cli/dist/analysis/ast-parser.js.map +1 -0
- package/cli/dist/analysis/complexity-analyzer.d.ts +27 -0
- package/cli/dist/analysis/complexity-analyzer.d.ts.map +1 -0
- package/cli/dist/analysis/complexity-analyzer.js +189 -0
- package/cli/dist/analysis/complexity-analyzer.js.map +1 -0
- package/cli/dist/analysis/dependency-analyzer.d.ts +23 -0
- package/cli/dist/analysis/dependency-analyzer.d.ts.map +1 -0
- package/cli/dist/analysis/dependency-analyzer.js +237 -0
- package/cli/dist/analysis/dependency-analyzer.js.map +1 -0
- package/cli/dist/analysis/index.d.ts +9 -0
- package/cli/dist/analysis/index.d.ts.map +1 -0
- package/cli/dist/analysis/index.js +25 -0
- package/cli/dist/analysis/index.js.map +1 -0
- package/cli/dist/analysis/security-scanner.d.ts +11 -0
- package/cli/dist/analysis/security-scanner.d.ts.map +1 -0
- package/cli/dist/analysis/security-scanner.js +294 -0
- package/cli/dist/analysis/security-scanner.js.map +1 -0
- package/cli/dist/analysis/types.d.ts +151 -0
- package/cli/dist/analysis/types.d.ts.map +1 -0
- package/cli/dist/analysis/types.js +6 -0
- package/cli/dist/analysis/types.js.map +1 -0
- package/cli/dist/cli.js +24 -0
- package/cli/dist/cli.js.map +1 -1
- package/cli/dist/commands/code-analysis.d.ts +11 -0
- package/cli/dist/commands/code-analysis.d.ts.map +1 -0
- package/cli/dist/commands/code-analysis.js +412 -0
- package/cli/dist/commands/code-analysis.js.map +1 -0
- package/modules.md +99 -3
- package/package.json +14 -2
- package/cli/dist/commands/agent.d.ts +0 -37
- package/cli/dist/commands/agent.d.ts.map +0 -1
- package/cli/dist/commands/agent.js +0 -222
- package/cli/dist/commands/agent.js.map +0 -1
- package/cli/dist/commands/beads.d.ts +0 -64
- package/cli/dist/commands/beads.d.ts.map +0 -1
- package/cli/dist/commands/beads.js +0 -377
- package/cli/dist/commands/beads.js.map +0 -1
- package/cli/dist/commands/change.d.ts +0 -54
- package/cli/dist/commands/change.d.ts.map +0 -1
- package/cli/dist/commands/change.js +0 -243
- package/cli/dist/commands/change.js.map +0 -1
- package/cli/dist/commands/clean.d.ts +0 -15
- package/cli/dist/commands/clean.d.ts.map +0 -1
- package/cli/dist/commands/clean.js +0 -63
- package/cli/dist/commands/clean.js.map +0 -1
- package/cli/dist/commands/clone.d.ts +0 -15
- package/cli/dist/commands/clone.d.ts.map +0 -1
- package/cli/dist/commands/clone.js +0 -49
- package/cli/dist/commands/clone.js.map +0 -1
- package/cli/dist/commands/config.d.ts +0 -33
- package/cli/dist/commands/config.d.ts.map +0 -1
- package/cli/dist/commands/config.js +0 -166
- package/cli/dist/commands/config.js.map +0 -1
- package/cli/dist/commands/context.d.ts +0 -38
- package/cli/dist/commands/context.d.ts.map +0 -1
- package/cli/dist/commands/context.js +0 -205
- package/cli/dist/commands/context.js.map +0 -1
- package/cli/dist/commands/create.d.ts +0 -18
- package/cli/dist/commands/create.d.ts.map +0 -1
- package/cli/dist/commands/create.js +0 -178
- package/cli/dist/commands/create.js.map +0 -1
- package/cli/dist/commands/diff.d.ts +0 -19
- package/cli/dist/commands/diff.d.ts.map +0 -1
- package/cli/dist/commands/diff.js +0 -104
- package/cli/dist/commands/diff.js.map +0 -1
- package/cli/dist/commands/doctor.d.ts +0 -14
- package/cli/dist/commands/doctor.d.ts.map +0 -1
- package/cli/dist/commands/doctor.js +0 -62
- package/cli/dist/commands/doctor.js.map +0 -1
- package/cli/dist/commands/export.d.ts +0 -28
- package/cli/dist/commands/export.d.ts.map +0 -1
- package/cli/dist/commands/export.js +0 -135
- package/cli/dist/commands/export.js.map +0 -1
- package/cli/dist/commands/import.d.ts +0 -23
- package/cli/dist/commands/import.d.ts.map +0 -1
- package/cli/dist/commands/import.js +0 -118
- package/cli/dist/commands/import.js.map +0 -1
- package/cli/dist/commands/prompt.d.ts +0 -45
- package/cli/dist/commands/prompt.d.ts.map +0 -1
- package/cli/dist/commands/prompt.js +0 -223
- package/cli/dist/commands/prompt.js.map +0 -1
- package/cli/dist/commands/spec.d.ts +0 -57
- package/cli/dist/commands/spec.d.ts.map +0 -1
- package/cli/dist/commands/spec.js +0 -279
- package/cli/dist/commands/spec.js.map +0 -1
- package/cli/dist/commands/stats.d.ts +0 -18
- package/cli/dist/commands/stats.d.ts.map +0 -1
- package/cli/dist/commands/stats.js +0 -85
- package/cli/dist/commands/stats.js.map +0 -1
- package/cli/dist/commands/task.d.ts +0 -65
- package/cli/dist/commands/task.d.ts.map +0 -1
- package/cli/dist/commands/task.js +0 -282
- package/cli/dist/commands/task.js.map +0 -1
- package/cli/dist/commands/template.d.ts +0 -17
- package/cli/dist/commands/template.d.ts.map +0 -1
- package/cli/dist/commands/template.js +0 -55
- package/cli/dist/commands/template.js.map +0 -1
- package/cli/dist/utils/agent-config.d.ts +0 -129
- package/cli/dist/utils/agent-config.d.ts.map +0 -1
- package/cli/dist/utils/agent-config.js +0 -297
- package/cli/dist/utils/agent-config.js.map +0 -1
- package/cli/dist/utils/beads-graph.d.ts +0 -17
- package/cli/dist/utils/beads-graph.d.ts.map +0 -1
- package/cli/dist/utils/beads-graph.js +0 -150
- package/cli/dist/utils/beads-graph.js.map +0 -1
- package/cli/dist/utils/beads-integration.d.ts +0 -112
- package/cli/dist/utils/beads-integration.d.ts.map +0 -1
- package/cli/dist/utils/beads-integration.js +0 -312
- package/cli/dist/utils/beads-integration.js.map +0 -1
- package/cli/dist/utils/beads-reporter.d.ts +0 -17
- package/cli/dist/utils/beads-reporter.d.ts.map +0 -1
- package/cli/dist/utils/beads-reporter.js +0 -160
- package/cli/dist/utils/beads-reporter.js.map +0 -1
- package/cli/dist/utils/cache-manager.d.ts +0 -55
- package/cli/dist/utils/cache-manager.d.ts.map +0 -1
- package/cli/dist/utils/cache-manager.js +0 -150
- package/cli/dist/utils/cache-manager.js.map +0 -1
- package/cli/dist/utils/change-manager.d.ts +0 -70
- package/cli/dist/utils/change-manager.d.ts.map +0 -1
- package/cli/dist/utils/change-manager.js +0 -412
- package/cli/dist/utils/change-manager.js.map +0 -1
- package/cli/dist/utils/config-manager-enhanced.d.ts +0 -66
- package/cli/dist/utils/config-manager-enhanced.d.ts.map +0 -1
- package/cli/dist/utils/config-manager-enhanced.js +0 -77
- package/cli/dist/utils/config-manager-enhanced.js.map +0 -1
- package/cli/dist/utils/context-manager.d.ts +0 -96
- package/cli/dist/utils/context-manager.d.ts.map +0 -1
- package/cli/dist/utils/context-manager.js +0 -258
- package/cli/dist/utils/context-manager.js.map +0 -1
- package/cli/dist/utils/diff-engine.d.ts +0 -78
- package/cli/dist/utils/diff-engine.d.ts.map +0 -1
- package/cli/dist/utils/diff-engine.js +0 -233
- package/cli/dist/utils/diff-engine.js.map +0 -1
- package/cli/dist/utils/export-system.d.ts +0 -101
- package/cli/dist/utils/export-system.d.ts.map +0 -1
- package/cli/dist/utils/export-system.js +0 -289
- package/cli/dist/utils/export-system.js.map +0 -1
- package/cli/dist/utils/health-checker.d.ts +0 -66
- package/cli/dist/utils/health-checker.d.ts.map +0 -1
- package/cli/dist/utils/health-checker.js +0 -285
- package/cli/dist/utils/health-checker.js.map +0 -1
- package/cli/dist/utils/import-system.d.ts +0 -74
- package/cli/dist/utils/import-system.d.ts.map +0 -1
- package/cli/dist/utils/import-system.js +0 -317
- package/cli/dist/utils/import-system.js.map +0 -1
- package/cli/dist/utils/module-cloner.d.ts +0 -40
- package/cli/dist/utils/module-cloner.d.ts.map +0 -1
- package/cli/dist/utils/module-cloner.js +0 -136
- package/cli/dist/utils/module-cloner.js.map +0 -1
- package/cli/dist/utils/prompt-manager.d.ts +0 -90
- package/cli/dist/utils/prompt-manager.d.ts.map +0 -1
- package/cli/dist/utils/prompt-manager.js +0 -302
- package/cli/dist/utils/prompt-manager.js.map +0 -1
- package/cli/dist/utils/spec-manager.d.ts +0 -65
- package/cli/dist/utils/spec-manager.d.ts.map +0 -1
- package/cli/dist/utils/spec-manager.js +0 -329
- package/cli/dist/utils/spec-manager.js.map +0 -1
- package/cli/dist/utils/stats-collector.d.ts +0 -74
- package/cli/dist/utils/stats-collector.d.ts.map +0 -1
- package/cli/dist/utils/stats-collector.js +0 -164
- package/cli/dist/utils/stats-collector.js.map +0 -1
- package/cli/dist/utils/template-engine.d.ts +0 -47
- package/cli/dist/utils/template-engine.d.ts.map +0 -1
- package/cli/dist/utils/template-engine.js +0 -204
- package/cli/dist/utils/template-engine.js.map +0 -1
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Cloud-Native Go Application AI Template
|
|
2
|
+
|
|
3
|
+
## Context
|
|
4
|
+
|
|
5
|
+
You are building a cloud-native Go application designed to run in Kubernetes or other container orchestration platforms.
|
|
6
|
+
|
|
7
|
+
## Key Requirements
|
|
8
|
+
|
|
9
|
+
### Kubernetes Integration
|
|
10
|
+
- Use `k8s.io/client-go` for Kubernetes API interactions
|
|
11
|
+
- Implement informers and listers for efficient resource watching
|
|
12
|
+
- Handle API errors using `k8s.io/apimachinery/pkg/api/errors`
|
|
13
|
+
- Use controller-runtime for custom controllers
|
|
14
|
+
- Implement leader election for high availability
|
|
15
|
+
|
|
16
|
+
### Configuration Management
|
|
17
|
+
- Load configuration from environment variables
|
|
18
|
+
- Support multiple configuration sources (env, files, config maps)
|
|
19
|
+
- Never hardcode secrets - use environment variables or secret managers
|
|
20
|
+
- Validate all configuration on startup
|
|
21
|
+
- Support hot reloading for non-critical configuration
|
|
22
|
+
|
|
23
|
+
### Health Checks
|
|
24
|
+
- Implement separate `/health` (liveness) and `/ready` (readiness) endpoints
|
|
25
|
+
- Keep health checks lightweight (<1s response time)
|
|
26
|
+
- Include dependency checks in readiness probes
|
|
27
|
+
- Return detailed status information with component-level details
|
|
28
|
+
- Implement graceful degradation for non-critical dependencies
|
|
29
|
+
|
|
30
|
+
### Graceful Shutdown
|
|
31
|
+
- Handle SIGTERM and SIGINT signals
|
|
32
|
+
- Implement graceful shutdown with timeout (typically 30s)
|
|
33
|
+
- Stop accepting new requests first
|
|
34
|
+
- Complete in-flight requests
|
|
35
|
+
- Close database connections and other resources
|
|
36
|
+
- Log shutdown progress
|
|
37
|
+
|
|
38
|
+
## Code Structure
|
|
39
|
+
|
|
40
|
+
```go
|
|
41
|
+
type Application struct {
|
|
42
|
+
config *Config
|
|
43
|
+
db *sql.DB
|
|
44
|
+
server *http.Server
|
|
45
|
+
checker *HealthChecker
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
func NewApplication(cfg *Config) (*Application, error) {
|
|
49
|
+
// Initialize dependencies
|
|
50
|
+
// Set up health checks
|
|
51
|
+
// Return configured application
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
func (app *Application) Start() error {
|
|
55
|
+
// Start HTTP server
|
|
56
|
+
// Start background workers
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
func (app *Application) Shutdown(ctx context.Context) error {
|
|
60
|
+
// Graceful shutdown logic
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Example Patterns
|
|
65
|
+
|
|
66
|
+
### Environment Configuration
|
|
67
|
+
```go
|
|
68
|
+
type Config struct {
|
|
69
|
+
Port int `envconfig:"PORT" default:"8080"`
|
|
70
|
+
DatabaseURL string `envconfig:"DATABASE_URL" required:"true"`
|
|
71
|
+
LogLevel string `envconfig:"LOG_LEVEL" default:"info"`
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Health Check Handler
|
|
76
|
+
```go
|
|
77
|
+
func (app *Application) readinessHandler(w http.ResponseWriter, r *http.Request) {
|
|
78
|
+
ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second)
|
|
79
|
+
defer cancel()
|
|
80
|
+
|
|
81
|
+
components, err := app.checker.Check(ctx)
|
|
82
|
+
// Return structured JSON response
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Graceful Shutdown
|
|
87
|
+
```go
|
|
88
|
+
quit := make(chan os.Signal, 1)
|
|
89
|
+
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
|
90
|
+
<-quit
|
|
91
|
+
|
|
92
|
+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
93
|
+
defer cancel()
|
|
94
|
+
|
|
95
|
+
if err := app.Shutdown(ctx); err != nil {
|
|
96
|
+
log.Fatalf("Shutdown failed: %v", err)
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Best Practices
|
|
101
|
+
|
|
102
|
+
1. **12-Factor App Principles**: Follow the twelve-factor app methodology
|
|
103
|
+
2. **Stateless Design**: Keep application stateless for horizontal scaling
|
|
104
|
+
3. **Observability**: Include structured logging, metrics, and tracing
|
|
105
|
+
4. **Resource Limits**: Set appropriate CPU and memory limits
|
|
106
|
+
5. **Security**: Run as non-root user, use read-only filesystems where possible
|
|
107
|
+
|
|
108
|
+
## Common Pitfalls to Avoid
|
|
109
|
+
|
|
110
|
+
- ❌ Hardcoding configuration values
|
|
111
|
+
- ❌ Not implementing health checks
|
|
112
|
+
- ❌ Ignoring shutdown signals
|
|
113
|
+
- ❌ Blocking operations in health checks
|
|
114
|
+
- ❌ Not validating configuration on startup
|
|
115
|
+
|
|
116
|
+
## References
|
|
117
|
+
|
|
118
|
+
- [Kubernetes Best Practices](https://kubernetes.io/docs/concepts/configuration/overview/)
|
|
119
|
+
- [The Twelve-Factor App](https://12factor.net/)
|
|
120
|
+
- [Go Cloud Development Kit](https://gocloud.dev/)
|
|
121
|
+
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# DevOps Tooling Go Application AI Template
|
|
2
|
+
|
|
3
|
+
## Context
|
|
4
|
+
|
|
5
|
+
You are building a DevOps automation tool in Go for deployment, infrastructure management, and CI/CD integration.
|
|
6
|
+
|
|
7
|
+
## Key Requirements
|
|
8
|
+
|
|
9
|
+
### CLI Framework
|
|
10
|
+
- Use Cobra for command-line interface with subcommands
|
|
11
|
+
- Implement proper flag parsing and validation
|
|
12
|
+
- Provide clear help text and usage examples
|
|
13
|
+
- Support configuration via environment variables and config files
|
|
14
|
+
|
|
15
|
+
### Automation Principles
|
|
16
|
+
- Implement idempotent operations (safe to retry)
|
|
17
|
+
- Provide detailed progress feedback for long-running operations
|
|
18
|
+
- Support dry-run mode for all destructive operations
|
|
19
|
+
- Implement rollback capability for failed deployments
|
|
20
|
+
- Log all operations with appropriate detail levels
|
|
21
|
+
|
|
22
|
+
### CI/CD Integration
|
|
23
|
+
- Return appropriate exit codes for pipeline integration
|
|
24
|
+
- Support environment-based configuration
|
|
25
|
+
- Generate machine-readable output (JSON, JUnit XML)
|
|
26
|
+
- Publish artifacts with checksums and metadata
|
|
27
|
+
- Implement health checks for deployment verification
|
|
28
|
+
|
|
29
|
+
### Infrastructure as Code
|
|
30
|
+
- Use declarative configuration (YAML/JSON)
|
|
31
|
+
- Implement state management for tracking resources
|
|
32
|
+
- Resolve resource dependencies correctly
|
|
33
|
+
- Detect configuration drift
|
|
34
|
+
- Support plan and apply workflow
|
|
35
|
+
|
|
36
|
+
## Code Structure
|
|
37
|
+
|
|
38
|
+
```go
|
|
39
|
+
type DeploymentConfig struct {
|
|
40
|
+
Name string
|
|
41
|
+
Environment string
|
|
42
|
+
Version string
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
type DeploymentOptions struct {
|
|
46
|
+
DryRun bool
|
|
47
|
+
Verbose bool
|
|
48
|
+
Timeout time.Duration
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
func Deploy(ctx context.Context, config *DeploymentConfig, opts *DeploymentOptions) error {
|
|
52
|
+
// Deployment logic with progress feedback
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Example Patterns
|
|
57
|
+
|
|
58
|
+
### Cobra CLI
|
|
59
|
+
```go
|
|
60
|
+
var rootCmd = &cobra.Command{
|
|
61
|
+
Use: "devops-tool",
|
|
62
|
+
Short: "A DevOps automation tool",
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
var deployCmd = &cobra.Command{
|
|
66
|
+
Use: "deploy [environment]",
|
|
67
|
+
Short: "Deploy application",
|
|
68
|
+
Args: cobra.ExactArgs(1),
|
|
69
|
+
RunE: func(cmd *cobra.Command, args []string) error {
|
|
70
|
+
return deployToEnvironment(args[0])
|
|
71
|
+
},
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
func init() {
|
|
75
|
+
deployCmd.Flags().StringP("version", "v", "latest", "Version to deploy")
|
|
76
|
+
deployCmd.Flags().BoolP("dry-run", "d", false, "Perform dry run")
|
|
77
|
+
rootCmd.AddCommand(deployCmd)
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Idempotent Operations
|
|
82
|
+
```go
|
|
83
|
+
func EnsureDeployment(ctx context.Context, config *DeploymentConfig) error {
|
|
84
|
+
existing, err := getDeployment(ctx, config.Name)
|
|
85
|
+
if err != nil && !isNotFoundError(err) {
|
|
86
|
+
return err
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if existing != nil {
|
|
90
|
+
if deploymentMatches(existing, config) {
|
|
91
|
+
log.Printf("Deployment already up to date")
|
|
92
|
+
return nil
|
|
93
|
+
}
|
|
94
|
+
return updateDeployment(ctx, config)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return createDeployment(ctx, config)
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Dry-Run Mode
|
|
102
|
+
```go
|
|
103
|
+
func Deploy(ctx context.Context, config *DeploymentConfig, opts *DeploymentOptions) error {
|
|
104
|
+
steps := []DeploymentStep{
|
|
105
|
+
{Name: "Validate", Fn: validateConfig},
|
|
106
|
+
{Name: "Build", Fn: buildImage},
|
|
107
|
+
{Name: "Deploy", Fn: updateDeployment},
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
for _, step := range steps {
|
|
111
|
+
if opts.DryRun {
|
|
112
|
+
log.Printf("[DRY RUN] Would execute: %s", step.Name)
|
|
113
|
+
continue
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if err := step.Fn(ctx, config); err != nil {
|
|
117
|
+
return err
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return nil
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Best Practices
|
|
126
|
+
|
|
127
|
+
1. **User Experience**: Provide clear, actionable error messages
|
|
128
|
+
2. **Safety**: Always confirm destructive operations
|
|
129
|
+
3. **Observability**: Log all operations with timestamps
|
|
130
|
+
4. **Resilience**: Implement retries with exponential backoff
|
|
131
|
+
5. **Documentation**: Include examples in help text
|
|
132
|
+
|
|
133
|
+
## Common Pitfalls to Avoid
|
|
134
|
+
|
|
135
|
+
- ❌ Not implementing dry-run mode
|
|
136
|
+
- ❌ Missing rollback capability
|
|
137
|
+
- ❌ Unclear error messages
|
|
138
|
+
- ❌ Not validating configuration before execution
|
|
139
|
+
- ❌ Hardcoding configuration values
|
|
140
|
+
|
|
141
|
+
## References
|
|
142
|
+
|
|
143
|
+
- [Cobra CLI Framework](https://github.com/spf13/cobra)
|
|
144
|
+
- [The Twelve-Factor App](https://12factor.net/)
|
|
145
|
+
- [Infrastructure as Code Principles](https://www.hashicorp.com/resources/what-is-infrastructure-as-code)
|
|
146
|
+
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# Distributed Systems Go Application AI Template
|
|
2
|
+
|
|
3
|
+
## Context
|
|
4
|
+
|
|
5
|
+
You are building a distributed system in Go with consensus, event sourcing, and distributed caching capabilities.
|
|
6
|
+
|
|
7
|
+
## Key Requirements
|
|
8
|
+
|
|
9
|
+
### Consensus and Coordination
|
|
10
|
+
- Use HashiCorp Raft or etcd/raft for consensus
|
|
11
|
+
- Implement proper FSM (Finite State Machine) with deterministic apply logic
|
|
12
|
+
- Handle leader election and follower states correctly
|
|
13
|
+
- Implement read consistency levels (strong vs eventual)
|
|
14
|
+
- Handle network partitions gracefully with retries
|
|
15
|
+
|
|
16
|
+
### Event Sourcing
|
|
17
|
+
- Design immutable events with all necessary information
|
|
18
|
+
- Implement event store interface for persistence
|
|
19
|
+
- Use aggregate root pattern for consistency boundaries
|
|
20
|
+
- Build projections for read models (CQRS pattern)
|
|
21
|
+
- Support event versioning for schema evolution
|
|
22
|
+
|
|
23
|
+
### Distributed Caching
|
|
24
|
+
- Implement cache-aside (lazy loading) pattern
|
|
25
|
+
- Set appropriate TTLs on all cached items
|
|
26
|
+
- Handle cache failures gracefully with fallback to database
|
|
27
|
+
- Implement cache invalidation on data changes
|
|
28
|
+
- Use pipelining for batch operations
|
|
29
|
+
|
|
30
|
+
## Code Structure
|
|
31
|
+
|
|
32
|
+
```go
|
|
33
|
+
// Event sourcing
|
|
34
|
+
type Event struct {
|
|
35
|
+
ID string
|
|
36
|
+
AggregateID string
|
|
37
|
+
Type string
|
|
38
|
+
Data json.RawMessage
|
|
39
|
+
Timestamp time.Time
|
|
40
|
+
Version int
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type EventStore interface {
|
|
44
|
+
Save(ctx context.Context, events []Event) error
|
|
45
|
+
Load(ctx context.Context, aggregateID string) ([]Event, error)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Caching
|
|
49
|
+
type CacheManager struct {
|
|
50
|
+
client *redis.Client
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
func (cm *CacheManager) Get(ctx context.Context, key string) (string, error)
|
|
54
|
+
func (cm *CacheManager) Set(ctx context.Context, key string, value interface{}, ttl time.Duration) error
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Example Patterns
|
|
58
|
+
|
|
59
|
+
### Consensus with Raft
|
|
60
|
+
```go
|
|
61
|
+
func NewRaftNode(nodeID, raftDir, raftBind string) (*raft.Raft, error) {
|
|
62
|
+
config := raft.DefaultConfig()
|
|
63
|
+
config.LocalID = raft.ServerID(nodeID)
|
|
64
|
+
|
|
65
|
+
store, _ := raftboltdb.NewBoltStore(filepath.Join(raftDir, "raft.db"))
|
|
66
|
+
snapshots, _ := raft.NewFileSnapshotStore(raftDir, 2, os.Stderr)
|
|
67
|
+
transport, _ := raft.NewTCPTransport(raftBind, nil, 3, 10*time.Second, os.Stderr)
|
|
68
|
+
|
|
69
|
+
return raft.NewRaft(config, fsm, store, store, snapshots, transport)
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Event Sourcing
|
|
74
|
+
```go
|
|
75
|
+
func (u *User) ChangeEmail(newEmail string) error {
|
|
76
|
+
event := Event{
|
|
77
|
+
ID: uuid.New().String(),
|
|
78
|
+
AggregateID: u.ID,
|
|
79
|
+
Type: "UserEmailChanged",
|
|
80
|
+
Data: json.Marshal(map[string]string{"new_email": newEmail}),
|
|
81
|
+
Timestamp: time.Now(),
|
|
82
|
+
Version: u.Version + 1,
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
u.changes = append(u.changes, event)
|
|
86
|
+
return u.ApplyEvent(event)
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Distributed Caching
|
|
91
|
+
```go
|
|
92
|
+
func GetUserWithCache(ctx context.Context, cache *redis.Client, db *sql.DB, userID string) (*User, error) {
|
|
93
|
+
// Try cache first
|
|
94
|
+
cacheKey := fmt.Sprintf("user:%s", userID)
|
|
95
|
+
if cached, err := cache.Get(ctx, cacheKey).Result(); err == nil {
|
|
96
|
+
var user User
|
|
97
|
+
json.Unmarshal([]byte(cached), &user)
|
|
98
|
+
return &user, nil
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Cache miss - load from database
|
|
102
|
+
user, _ := loadUserFromDB(ctx, db, userID)
|
|
103
|
+
|
|
104
|
+
// Store in cache
|
|
105
|
+
data, _ := json.Marshal(user)
|
|
106
|
+
cache.Set(ctx, cacheKey, data, 1*time.Hour)
|
|
107
|
+
|
|
108
|
+
return user, nil
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Best Practices
|
|
113
|
+
|
|
114
|
+
1. **Idempotency**: All operations should be idempotent
|
|
115
|
+
2. **Timeouts**: Set appropriate timeouts for all distributed operations
|
|
116
|
+
3. **Retries**: Implement exponential backoff for retries
|
|
117
|
+
4. **Monitoring**: Add metrics for consensus state, cache hit rates, event processing
|
|
118
|
+
5. **Testing**: Test network partition scenarios
|
|
119
|
+
|
|
120
|
+
## Common Pitfalls to Avoid
|
|
121
|
+
|
|
122
|
+
- ❌ Not handling leader election failures
|
|
123
|
+
- ❌ Mutable events in event sourcing
|
|
124
|
+
- ❌ Not setting TTLs on cached items
|
|
125
|
+
- ❌ Blocking operations in FSM apply
|
|
126
|
+
- ❌ Not implementing proper snapshot/restore
|
|
127
|
+
|
|
128
|
+
## References
|
|
129
|
+
|
|
130
|
+
- [HashiCorp Raft](https://github.com/hashicorp/raft)
|
|
131
|
+
- [Event Sourcing Pattern](https://martinfowler.com/eaaDev/EventSourcing.html)
|
|
132
|
+
- [Redis Best Practices](https://redis.io/docs/manual/patterns/)
|
|
133
|
+
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# Microservice Project Template
|
|
2
|
+
|
|
3
|
+
## Context
|
|
4
|
+
|
|
5
|
+
You are generating Go code for a **microservice** project. This includes gRPC services, service discovery, distributed tracing, and metrics.
|
|
6
|
+
|
|
7
|
+
## Standards
|
|
8
|
+
|
|
9
|
+
Follow these Go coding standards for microservices:
|
|
10
|
+
|
|
11
|
+
### Universal Rules
|
|
12
|
+
|
|
13
|
+
1. **Naming Conventions**: Use MixedCaps for exported names, mixedCaps for unexported
|
|
14
|
+
2. **Error Handling**: Return errors explicitly, use `errors.Is/As` for error inspection
|
|
15
|
+
3. **Concurrency**: Use goroutines and channels properly, always pass context
|
|
16
|
+
4. **Testing**: Write table-driven tests, use mocks for external dependencies
|
|
17
|
+
5. **Code Organization**: Keep packages flat and focused
|
|
18
|
+
6. **Documentation**: Add godoc comments for all exported functions
|
|
19
|
+
7. **Performance**: Minimize allocations, use connection pooling
|
|
20
|
+
|
|
21
|
+
### Microservices Rules
|
|
22
|
+
|
|
23
|
+
#### gRPC Services
|
|
24
|
+
- Define services using Protocol Buffers (proto3)
|
|
25
|
+
- Use gRPC status codes for errors (InvalidArgument, NotFound, Internal, etc.)
|
|
26
|
+
- Implement unary and stream interceptors for logging, auth, metrics
|
|
27
|
+
- Set appropriate timeouts using context (typically 5 seconds)
|
|
28
|
+
- Use server-side streaming for large result sets
|
|
29
|
+
|
|
30
|
+
#### Service Discovery
|
|
31
|
+
- Register service with discovery system (Consul, etcd, Kubernetes) on startup
|
|
32
|
+
- Implement `/health` and `/ready` endpoints for health checks
|
|
33
|
+
- Deregister service during graceful shutdown
|
|
34
|
+
- Use service discovery client to find other services
|
|
35
|
+
- Handle service unavailability gracefully
|
|
36
|
+
|
|
37
|
+
#### Distributed Tracing
|
|
38
|
+
- Initialize OpenTelemetry tracer on startup
|
|
39
|
+
- Create spans for significant operations
|
|
40
|
+
- Propagate trace context across service boundaries
|
|
41
|
+
- Add relevant attributes to spans (user_id, order_id, etc.)
|
|
42
|
+
- Record errors in spans
|
|
43
|
+
|
|
44
|
+
#### Metrics
|
|
45
|
+
- Implement RED metrics (Rate, Errors, Duration)
|
|
46
|
+
- Use appropriate metric types (Counter, Gauge, Histogram)
|
|
47
|
+
- Expose metrics on `/metrics` endpoint
|
|
48
|
+
- Add business-specific metrics
|
|
49
|
+
- Avoid high cardinality labels
|
|
50
|
+
|
|
51
|
+
## Key Requirements
|
|
52
|
+
|
|
53
|
+
### gRPC Server Setup
|
|
54
|
+
```go
|
|
55
|
+
grpcServer := grpc.NewServer(
|
|
56
|
+
grpc.ChainUnaryInterceptor(
|
|
57
|
+
recoveryUnaryInterceptor(logger),
|
|
58
|
+
loggingUnaryInterceptor(logger),
|
|
59
|
+
metricsUnaryInterceptor(),
|
|
60
|
+
),
|
|
61
|
+
)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Service Implementation Pattern
|
|
65
|
+
```go
|
|
66
|
+
func (s *UserService) GetUser(ctx context.Context, req *userv1.GetUserRequest) (*userv1.GetUserResponse, error) {
|
|
67
|
+
if req.Id <= 0 {
|
|
68
|
+
return nil, status.Error(codes.InvalidArgument, "user ID must be positive")
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
user, err := s.repo.GetUser(ctx, req.Id)
|
|
72
|
+
if err != nil {
|
|
73
|
+
if errors.Is(err, ErrNotFound) {
|
|
74
|
+
return nil, status.Error(codes.NotFound, "user not found")
|
|
75
|
+
}
|
|
76
|
+
return nil, status.Error(codes.Internal, "internal error")
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return &userv1.GetUserResponse{User: user}, nil
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Service Registration
|
|
84
|
+
```go
|
|
85
|
+
func (r *ServiceRegistry) Register(ctx context.Context) error {
|
|
86
|
+
registration := &api.AgentServiceRegistration{
|
|
87
|
+
ID: r.serviceID,
|
|
88
|
+
Name: r.serviceName,
|
|
89
|
+
Port: r.port,
|
|
90
|
+
Address: getLocalIP(),
|
|
91
|
+
Check: &api.AgentServiceCheck{
|
|
92
|
+
HTTP: fmt.Sprintf("http://%s:%d/health", getLocalIP(), r.port),
|
|
93
|
+
Interval: "10s",
|
|
94
|
+
Timeout: "3s",
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
return r.client.Agent().ServiceRegister(registration)
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Distributed Tracing
|
|
102
|
+
```go
|
|
103
|
+
func (s *UserService) GetUser(ctx context.Context, id int64) (*User, error) {
|
|
104
|
+
tracer := otel.Tracer("user-service")
|
|
105
|
+
ctx, span := tracer.Start(ctx, "GetUser")
|
|
106
|
+
defer span.End()
|
|
107
|
+
|
|
108
|
+
span.SetAttributes(attribute.Int64("user.id", id))
|
|
109
|
+
|
|
110
|
+
user, err := s.repo.GetUser(ctx, id)
|
|
111
|
+
if err != nil {
|
|
112
|
+
span.RecordError(err)
|
|
113
|
+
span.SetStatus(codes.Error, err.Error())
|
|
114
|
+
return nil, err
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return user, nil
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Metrics
|
|
122
|
+
```go
|
|
123
|
+
var (
|
|
124
|
+
requestsTotal = promauto.NewCounterVec(
|
|
125
|
+
prometheus.CounterOpts{
|
|
126
|
+
Name: "grpc_requests_total",
|
|
127
|
+
Help: "Total gRPC requests",
|
|
128
|
+
},
|
|
129
|
+
[]string{"method", "status"},
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
requestDuration = promauto.NewHistogramVec(
|
|
133
|
+
prometheus.HistogramOpts{
|
|
134
|
+
Name: "grpc_request_duration_seconds",
|
|
135
|
+
Help: "gRPC request duration",
|
|
136
|
+
Buckets: prometheus.DefBuckets,
|
|
137
|
+
},
|
|
138
|
+
[]string{"method"},
|
|
139
|
+
)
|
|
140
|
+
)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Common Patterns
|
|
144
|
+
|
|
145
|
+
### Proto3 Service Definition
|
|
146
|
+
```protobuf
|
|
147
|
+
syntax = "proto3";
|
|
148
|
+
|
|
149
|
+
package user.v1;
|
|
150
|
+
|
|
151
|
+
service UserService {
|
|
152
|
+
rpc GetUser(GetUserRequest) returns (GetUserResponse);
|
|
153
|
+
rpc CreateUser(CreateUserRequest) returns (CreateUserResponse);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
message User {
|
|
157
|
+
int64 id = 1;
|
|
158
|
+
string name = 2;
|
|
159
|
+
string email = 3;
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Health Check Endpoints
|
|
164
|
+
```go
|
|
165
|
+
func (h *HealthChecker) Ready(w http.ResponseWriter, r *http.Request) {
|
|
166
|
+
ctx, cancel := context.WithTimeout(r.Context(), 2*time.Second)
|
|
167
|
+
defer cancel()
|
|
168
|
+
|
|
169
|
+
if err := h.db.PingContext(ctx); err != nil {
|
|
170
|
+
w.WriteHeader(http.StatusServiceUnavailable)
|
|
171
|
+
return
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
w.WriteHeader(http.StatusOK)
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Graceful Shutdown
|
|
179
|
+
```go
|
|
180
|
+
func main() {
|
|
181
|
+
srv := NewServer()
|
|
182
|
+
registry := NewServiceRegistry()
|
|
183
|
+
|
|
184
|
+
registry.Register(context.Background())
|
|
185
|
+
|
|
186
|
+
go srv.Start()
|
|
187
|
+
|
|
188
|
+
quit := make(chan os.Signal, 1)
|
|
189
|
+
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
|
190
|
+
<-quit
|
|
191
|
+
|
|
192
|
+
registry.Deregister()
|
|
193
|
+
srv.Stop()
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Tools
|
|
198
|
+
|
|
199
|
+
Ensure generated code passes:
|
|
200
|
+
- `go build` - Compiles without errors
|
|
201
|
+
- `golangci-lint run` - Passes all linters
|
|
202
|
+
- `go vet` - No suspicious constructs
|
|
203
|
+
- `gofmt -d .` - Properly formatted
|
|
204
|
+
- `go test -race` - No race conditions
|
|
205
|
+
|
|
206
|
+
## Output Format
|
|
207
|
+
|
|
208
|
+
Generate complete, production-ready Go code with:
|
|
209
|
+
- Package declaration and imports
|
|
210
|
+
- Protocol Buffer definitions (if applicable)
|
|
211
|
+
- gRPC service implementation
|
|
212
|
+
- Interceptors for logging, recovery, metrics
|
|
213
|
+
- Service registration/discovery
|
|
214
|
+
- Distributed tracing instrumentation
|
|
215
|
+
- Prometheus metrics
|
|
216
|
+
- Graceful shutdown
|
|
217
|
+
- Comprehensive godoc comments
|
|
218
|
+
|
|
219
|
+
## References
|
|
220
|
+
|
|
221
|
+
- [gRPC Go](https://grpc.io/docs/languages/go/)
|
|
222
|
+
- [OpenTelemetry Go](https://opentelemetry.io/docs/instrumentation/go/)
|
|
223
|
+
- [Prometheus Go Client](https://github.com/prometheus/client_golang)
|
|
224
|
+
- [Consul Service Discovery](https://www.consul.io/)
|
|
225
|
+
|