@wazir-dev/cli 1.0.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/AGENTS.md +111 -0
- package/CHANGELOG.md +14 -0
- package/CONTRIBUTING.md +101 -0
- package/LICENSE +21 -0
- package/README.md +314 -0
- package/assets/composition-engine.mmd +34 -0
- package/assets/demo-script.sh +17 -0
- package/assets/logo-dark.svg +14 -0
- package/assets/logo.svg +14 -0
- package/assets/pipeline.mmd +39 -0
- package/assets/record-demo.sh +51 -0
- package/docs/README.md +51 -0
- package/docs/adapters/context-mode.md +60 -0
- package/docs/concepts/architecture.md +87 -0
- package/docs/concepts/artifact-model.md +60 -0
- package/docs/concepts/composition-engine.md +36 -0
- package/docs/concepts/indexing-and-recall.md +160 -0
- package/docs/concepts/observability.md +41 -0
- package/docs/concepts/roles-and-workflows.md +59 -0
- package/docs/concepts/terminology-policy.md +27 -0
- package/docs/getting-started/01-installation.md +78 -0
- package/docs/getting-started/02-first-run.md +102 -0
- package/docs/getting-started/03-adding-to-project.md +15 -0
- package/docs/getting-started/04-host-setup.md +15 -0
- package/docs/guides/ci-integration.md +15 -0
- package/docs/guides/creating-skills.md +15 -0
- package/docs/guides/expertise-module-authoring.md +15 -0
- package/docs/guides/hook-development.md +15 -0
- package/docs/guides/memory-and-learnings.md +34 -0
- package/docs/guides/multi-host-export.md +15 -0
- package/docs/guides/troubleshooting.md +101 -0
- package/docs/guides/writing-custom-roles.md +15 -0
- package/docs/plans/2026-03-15-cli-pipeline-integration-design.md +592 -0
- package/docs/plans/2026-03-15-cli-pipeline-integration-plan.md +598 -0
- package/docs/plans/2026-03-15-docs-enforcement-plan.md +238 -0
- package/docs/readmes/INDEX.md +99 -0
- package/docs/readmes/features/expertise/README.md +171 -0
- package/docs/readmes/features/exports/README.md +222 -0
- package/docs/readmes/features/hooks/README.md +103 -0
- package/docs/readmes/features/hooks/loop-cap-guard.md +133 -0
- package/docs/readmes/features/hooks/post-tool-capture.md +121 -0
- package/docs/readmes/features/hooks/post-tool-lint.md +130 -0
- package/docs/readmes/features/hooks/pre-compact-summary.md +122 -0
- package/docs/readmes/features/hooks/pre-tool-capture-route.md +100 -0
- package/docs/readmes/features/hooks/protected-path-write-guard.md +128 -0
- package/docs/readmes/features/hooks/session-start.md +119 -0
- package/docs/readmes/features/hooks/stop-handoff-harvest.md +125 -0
- package/docs/readmes/features/roles/README.md +157 -0
- package/docs/readmes/features/roles/clarifier.md +152 -0
- package/docs/readmes/features/roles/content-author.md +190 -0
- package/docs/readmes/features/roles/designer.md +193 -0
- package/docs/readmes/features/roles/executor.md +184 -0
- package/docs/readmes/features/roles/learner.md +210 -0
- package/docs/readmes/features/roles/planner.md +182 -0
- package/docs/readmes/features/roles/researcher.md +164 -0
- package/docs/readmes/features/roles/reviewer.md +184 -0
- package/docs/readmes/features/roles/specifier.md +162 -0
- package/docs/readmes/features/roles/verifier.md +215 -0
- package/docs/readmes/features/schemas/README.md +178 -0
- package/docs/readmes/features/skills/README.md +63 -0
- package/docs/readmes/features/skills/brainstorming.md +96 -0
- package/docs/readmes/features/skills/debugging.md +148 -0
- package/docs/readmes/features/skills/design.md +120 -0
- package/docs/readmes/features/skills/prepare-next.md +109 -0
- package/docs/readmes/features/skills/run-audit.md +159 -0
- package/docs/readmes/features/skills/scan-project.md +109 -0
- package/docs/readmes/features/skills/self-audit.md +176 -0
- package/docs/readmes/features/skills/tdd.md +137 -0
- package/docs/readmes/features/skills/using-skills.md +92 -0
- package/docs/readmes/features/skills/verification.md +120 -0
- package/docs/readmes/features/skills/writing-plans.md +104 -0
- package/docs/readmes/features/tooling/README.md +320 -0
- package/docs/readmes/features/workflows/README.md +186 -0
- package/docs/readmes/features/workflows/author.md +181 -0
- package/docs/readmes/features/workflows/clarify.md +154 -0
- package/docs/readmes/features/workflows/design-review.md +171 -0
- package/docs/readmes/features/workflows/design.md +169 -0
- package/docs/readmes/features/workflows/discover.md +162 -0
- package/docs/readmes/features/workflows/execute.md +173 -0
- package/docs/readmes/features/workflows/learn.md +167 -0
- package/docs/readmes/features/workflows/plan-review.md +165 -0
- package/docs/readmes/features/workflows/plan.md +170 -0
- package/docs/readmes/features/workflows/prepare-next.md +167 -0
- package/docs/readmes/features/workflows/review.md +169 -0
- package/docs/readmes/features/workflows/run-audit.md +191 -0
- package/docs/readmes/features/workflows/spec-challenge.md +159 -0
- package/docs/readmes/features/workflows/specify.md +160 -0
- package/docs/readmes/features/workflows/verify.md +177 -0
- package/docs/readmes/packages/README.md +50 -0
- package/docs/readmes/packages/ajv.md +117 -0
- package/docs/readmes/packages/context-mode.md +118 -0
- package/docs/readmes/packages/gray-matter.md +116 -0
- package/docs/readmes/packages/node-test.md +137 -0
- package/docs/readmes/packages/yaml.md +112 -0
- package/docs/reference/configuration-reference.md +159 -0
- package/docs/reference/expertise-index.md +52 -0
- package/docs/reference/git-flow.md +43 -0
- package/docs/reference/hooks.md +87 -0
- package/docs/reference/host-exports.md +50 -0
- package/docs/reference/launch-checklist.md +172 -0
- package/docs/reference/marketplace-listings.md +76 -0
- package/docs/reference/release-process.md +34 -0
- package/docs/reference/roles-reference.md +77 -0
- package/docs/reference/skills.md +33 -0
- package/docs/reference/templates.md +29 -0
- package/docs/reference/tooling-cli.md +94 -0
- package/docs/truth-claims.yaml +222 -0
- package/expertise/PROGRESS.md +63 -0
- package/expertise/README.md +18 -0
- package/expertise/antipatterns/PROGRESS.md +56 -0
- package/expertise/antipatterns/backend/api-design-antipatterns.md +1271 -0
- package/expertise/antipatterns/backend/auth-antipatterns.md +1195 -0
- package/expertise/antipatterns/backend/caching-antipatterns.md +622 -0
- package/expertise/antipatterns/backend/database-antipatterns.md +1038 -0
- package/expertise/antipatterns/backend/index.md +24 -0
- package/expertise/antipatterns/backend/microservices-antipatterns.md +850 -0
- package/expertise/antipatterns/code/architecture-antipatterns.md +919 -0
- package/expertise/antipatterns/code/async-antipatterns.md +622 -0
- package/expertise/antipatterns/code/code-smells.md +1186 -0
- package/expertise/antipatterns/code/dependency-antipatterns.md +1209 -0
- package/expertise/antipatterns/code/error-handling-antipatterns.md +1360 -0
- package/expertise/antipatterns/code/index.md +27 -0
- package/expertise/antipatterns/code/naming-and-abstraction.md +1118 -0
- package/expertise/antipatterns/code/state-management-antipatterns.md +1076 -0
- package/expertise/antipatterns/code/testing-antipatterns.md +1053 -0
- package/expertise/antipatterns/design/accessibility-antipatterns.md +1136 -0
- package/expertise/antipatterns/design/dark-patterns.md +1121 -0
- package/expertise/antipatterns/design/index.md +22 -0
- package/expertise/antipatterns/design/ui-antipatterns.md +1202 -0
- package/expertise/antipatterns/design/ux-antipatterns.md +680 -0
- package/expertise/antipatterns/frontend/css-layout-antipatterns.md +691 -0
- package/expertise/antipatterns/frontend/flutter-antipatterns.md +1827 -0
- package/expertise/antipatterns/frontend/index.md +23 -0
- package/expertise/antipatterns/frontend/mobile-antipatterns.md +573 -0
- package/expertise/antipatterns/frontend/react-antipatterns.md +1128 -0
- package/expertise/antipatterns/frontend/spa-antipatterns.md +1235 -0
- package/expertise/antipatterns/index.md +31 -0
- package/expertise/antipatterns/performance/index.md +20 -0
- package/expertise/antipatterns/performance/performance-antipatterns.md +1013 -0
- package/expertise/antipatterns/performance/premature-optimization.md +623 -0
- package/expertise/antipatterns/performance/scaling-antipatterns.md +785 -0
- package/expertise/antipatterns/process/ai-coding-antipatterns.md +853 -0
- package/expertise/antipatterns/process/code-review-antipatterns.md +656 -0
- package/expertise/antipatterns/process/deployment-antipatterns.md +920 -0
- package/expertise/antipatterns/process/index.md +23 -0
- package/expertise/antipatterns/process/technical-debt-antipatterns.md +647 -0
- package/expertise/antipatterns/security/index.md +20 -0
- package/expertise/antipatterns/security/secrets-antipatterns.md +849 -0
- package/expertise/antipatterns/security/security-theater.md +843 -0
- package/expertise/antipatterns/security/vulnerability-patterns.md +801 -0
- package/expertise/architecture/PROGRESS.md +70 -0
- package/expertise/architecture/data/caching-architecture.md +671 -0
- package/expertise/architecture/data/data-consistency.md +574 -0
- package/expertise/architecture/data/data-modeling.md +536 -0
- package/expertise/architecture/data/event-streams-and-queues.md +634 -0
- package/expertise/architecture/data/index.md +25 -0
- package/expertise/architecture/data/search-architecture.md +663 -0
- package/expertise/architecture/data/sql-vs-nosql.md +708 -0
- package/expertise/architecture/decisions/architecture-decision-records.md +640 -0
- package/expertise/architecture/decisions/build-vs-buy.md +616 -0
- package/expertise/architecture/decisions/index.md +23 -0
- package/expertise/architecture/decisions/monolith-to-microservices.md +790 -0
- package/expertise/architecture/decisions/technology-selection.md +616 -0
- package/expertise/architecture/distributed/cap-theorem-and-tradeoffs.md +800 -0
- package/expertise/architecture/distributed/circuit-breaker-bulkhead.md +741 -0
- package/expertise/architecture/distributed/consensus-and-coordination.md +796 -0
- package/expertise/architecture/distributed/distributed-systems-fundamentals.md +564 -0
- package/expertise/architecture/distributed/idempotency-and-retry.md +796 -0
- package/expertise/architecture/distributed/index.md +25 -0
- package/expertise/architecture/distributed/saga-pattern.md +797 -0
- package/expertise/architecture/foundations/architectural-thinking.md +460 -0
- package/expertise/architecture/foundations/coupling-and-cohesion.md +770 -0
- package/expertise/architecture/foundations/design-principles-solid.md +649 -0
- package/expertise/architecture/foundations/domain-driven-design.md +719 -0
- package/expertise/architecture/foundations/index.md +25 -0
- package/expertise/architecture/foundations/separation-of-concerns.md +472 -0
- package/expertise/architecture/foundations/twelve-factor-app.md +797 -0
- package/expertise/architecture/index.md +34 -0
- package/expertise/architecture/integration/api-design-graphql.md +638 -0
- package/expertise/architecture/integration/api-design-grpc.md +804 -0
- package/expertise/architecture/integration/api-design-rest.md +892 -0
- package/expertise/architecture/integration/index.md +25 -0
- package/expertise/architecture/integration/third-party-integration.md +795 -0
- package/expertise/architecture/integration/webhooks-and-callbacks.md +1152 -0
- package/expertise/architecture/integration/websockets-realtime.md +791 -0
- package/expertise/architecture/mobile-architecture/index.md +22 -0
- package/expertise/architecture/mobile-architecture/mobile-app-architecture.md +780 -0
- package/expertise/architecture/mobile-architecture/mobile-backend-for-frontend.md +670 -0
- package/expertise/architecture/mobile-architecture/offline-first.md +719 -0
- package/expertise/architecture/mobile-architecture/push-and-sync.md +782 -0
- package/expertise/architecture/patterns/cqrs-event-sourcing.md +717 -0
- package/expertise/architecture/patterns/event-driven.md +797 -0
- package/expertise/architecture/patterns/hexagonal-clean-architecture.md +870 -0
- package/expertise/architecture/patterns/index.md +27 -0
- package/expertise/architecture/patterns/layered-architecture.md +736 -0
- package/expertise/architecture/patterns/microservices.md +753 -0
- package/expertise/architecture/patterns/modular-monolith.md +692 -0
- package/expertise/architecture/patterns/monolith.md +626 -0
- package/expertise/architecture/patterns/plugin-architecture.md +735 -0
- package/expertise/architecture/patterns/serverless.md +780 -0
- package/expertise/architecture/scaling/database-scaling.md +615 -0
- package/expertise/architecture/scaling/feature-flags-and-rollouts.md +757 -0
- package/expertise/architecture/scaling/horizontal-vs-vertical.md +606 -0
- package/expertise/architecture/scaling/index.md +24 -0
- package/expertise/architecture/scaling/multi-tenancy.md +800 -0
- package/expertise/architecture/scaling/stateless-design.md +787 -0
- package/expertise/backend/embedded-firmware.md +625 -0
- package/expertise/backend/go.md +853 -0
- package/expertise/backend/index.md +24 -0
- package/expertise/backend/java-spring.md +448 -0
- package/expertise/backend/node-typescript.md +625 -0
- package/expertise/backend/python-fastapi.md +724 -0
- package/expertise/backend/rust.md +458 -0
- package/expertise/backend/solidity.md +711 -0
- package/expertise/composition-map.yaml +443 -0
- package/expertise/content/foundations/content-modeling.md +395 -0
- package/expertise/content/foundations/editorial-standards.md +449 -0
- package/expertise/content/foundations/index.md +24 -0
- package/expertise/content/foundations/microcopy.md +455 -0
- package/expertise/content/foundations/terminology-governance.md +509 -0
- package/expertise/content/index.md +34 -0
- package/expertise/content/patterns/accessibility-copy.md +518 -0
- package/expertise/content/patterns/index.md +24 -0
- package/expertise/content/patterns/notification-content.md +433 -0
- package/expertise/content/patterns/sample-content.md +486 -0
- package/expertise/content/patterns/state-copy.md +439 -0
- package/expertise/design/PROGRESS.md +58 -0
- package/expertise/design/disciplines/dark-mode-theming.md +577 -0
- package/expertise/design/disciplines/design-systems.md +595 -0
- package/expertise/design/disciplines/index.md +25 -0
- package/expertise/design/disciplines/information-architecture.md +800 -0
- package/expertise/design/disciplines/interaction-design.md +788 -0
- package/expertise/design/disciplines/responsive-design.md +552 -0
- package/expertise/design/disciplines/usability-testing.md +516 -0
- package/expertise/design/disciplines/user-research.md +792 -0
- package/expertise/design/foundations/accessibility-design.md +796 -0
- package/expertise/design/foundations/color-theory.md +797 -0
- package/expertise/design/foundations/iconography.md +795 -0
- package/expertise/design/foundations/index.md +26 -0
- package/expertise/design/foundations/motion-and-animation.md +653 -0
- package/expertise/design/foundations/rtl-design.md +585 -0
- package/expertise/design/foundations/spacing-and-layout.md +607 -0
- package/expertise/design/foundations/typography.md +800 -0
- package/expertise/design/foundations/visual-hierarchy.md +761 -0
- package/expertise/design/index.md +32 -0
- package/expertise/design/patterns/authentication-flows.md +474 -0
- package/expertise/design/patterns/content-consumption.md +789 -0
- package/expertise/design/patterns/data-display.md +618 -0
- package/expertise/design/patterns/e-commerce.md +1494 -0
- package/expertise/design/patterns/feedback-and-states.md +642 -0
- package/expertise/design/patterns/forms-and-input.md +819 -0
- package/expertise/design/patterns/gamification.md +801 -0
- package/expertise/design/patterns/index.md +31 -0
- package/expertise/design/patterns/microinteractions.md +449 -0
- package/expertise/design/patterns/navigation.md +800 -0
- package/expertise/design/patterns/notifications.md +705 -0
- package/expertise/design/patterns/onboarding.md +700 -0
- package/expertise/design/patterns/search-and-filter.md +601 -0
- package/expertise/design/patterns/settings-and-preferences.md +768 -0
- package/expertise/design/patterns/social-and-community.md +748 -0
- package/expertise/design/platforms/desktop-native.md +612 -0
- package/expertise/design/platforms/index.md +25 -0
- package/expertise/design/platforms/mobile-android.md +825 -0
- package/expertise/design/platforms/mobile-cross-platform.md +983 -0
- package/expertise/design/platforms/mobile-ios.md +699 -0
- package/expertise/design/platforms/tablet.md +794 -0
- package/expertise/design/platforms/web-dashboard.md +790 -0
- package/expertise/design/platforms/web-responsive.md +550 -0
- package/expertise/design/psychology/behavioral-nudges.md +449 -0
- package/expertise/design/psychology/cognitive-load.md +1191 -0
- package/expertise/design/psychology/error-psychology.md +778 -0
- package/expertise/design/psychology/index.md +22 -0
- package/expertise/design/psychology/persuasive-design.md +736 -0
- package/expertise/design/psychology/user-mental-models.md +623 -0
- package/expertise/design/tooling/open-pencil.md +266 -0
- package/expertise/frontend/angular.md +1073 -0
- package/expertise/frontend/desktop-electron.md +546 -0
- package/expertise/frontend/flutter.md +782 -0
- package/expertise/frontend/index.md +27 -0
- package/expertise/frontend/native-android.md +409 -0
- package/expertise/frontend/native-ios.md +490 -0
- package/expertise/frontend/react-native.md +1160 -0
- package/expertise/frontend/react.md +808 -0
- package/expertise/frontend/vue.md +1089 -0
- package/expertise/humanize/domain-rules-code.md +79 -0
- package/expertise/humanize/domain-rules-content.md +67 -0
- package/expertise/humanize/domain-rules-technical-docs.md +56 -0
- package/expertise/humanize/index.md +35 -0
- package/expertise/humanize/self-audit-checklist.md +87 -0
- package/expertise/humanize/sentence-patterns.md +218 -0
- package/expertise/humanize/vocabulary-blacklist.md +105 -0
- package/expertise/i18n/PROGRESS.md +65 -0
- package/expertise/i18n/advanced/accessibility-and-i18n.md +28 -0
- package/expertise/i18n/advanced/bidirectional-text-algorithm.md +38 -0
- package/expertise/i18n/advanced/complex-scripts.md +30 -0
- package/expertise/i18n/advanced/performance-and-i18n.md +27 -0
- package/expertise/i18n/advanced/testing-i18n.md +28 -0
- package/expertise/i18n/content/content-adaptation.md +23 -0
- package/expertise/i18n/content/locale-specific-formatting.md +23 -0
- package/expertise/i18n/content/machine-translation-integration.md +28 -0
- package/expertise/i18n/content/translation-management.md +29 -0
- package/expertise/i18n/foundations/date-time-calendars.md +67 -0
- package/expertise/i18n/foundations/i18n-architecture.md +272 -0
- package/expertise/i18n/foundations/locale-and-language-tags.md +79 -0
- package/expertise/i18n/foundations/numbers-currency-units.md +61 -0
- package/expertise/i18n/foundations/pluralization-and-gender.md +109 -0
- package/expertise/i18n/foundations/string-externalization.md +236 -0
- package/expertise/i18n/foundations/text-direction-bidi.md +241 -0
- package/expertise/i18n/foundations/unicode-and-encoding.md +86 -0
- package/expertise/i18n/index.md +38 -0
- package/expertise/i18n/platform/backend-i18n.md +31 -0
- package/expertise/i18n/platform/flutter-i18n.md +148 -0
- package/expertise/i18n/platform/native-android-i18n.md +36 -0
- package/expertise/i18n/platform/native-ios-i18n.md +36 -0
- package/expertise/i18n/platform/react-i18n.md +103 -0
- package/expertise/i18n/platform/web-css-i18n.md +81 -0
- package/expertise/i18n/rtl/arabic-specific.md +175 -0
- package/expertise/i18n/rtl/hebrew-specific.md +149 -0
- package/expertise/i18n/rtl/rtl-animations-and-transitions.md +111 -0
- package/expertise/i18n/rtl/rtl-forms-and-input.md +161 -0
- package/expertise/i18n/rtl/rtl-fundamentals.md +211 -0
- package/expertise/i18n/rtl/rtl-icons-and-images.md +181 -0
- package/expertise/i18n/rtl/rtl-layout-mirroring.md +252 -0
- package/expertise/i18n/rtl/rtl-navigation-and-gestures.md +107 -0
- package/expertise/i18n/rtl/rtl-testing-and-qa.md +147 -0
- package/expertise/i18n/rtl/rtl-typography.md +160 -0
- package/expertise/index.md +113 -0
- package/expertise/index.yaml +216 -0
- package/expertise/infrastructure/cloud-aws.md +597 -0
- package/expertise/infrastructure/cloud-gcp.md +599 -0
- package/expertise/infrastructure/cybersecurity.md +816 -0
- package/expertise/infrastructure/database-mongodb.md +447 -0
- package/expertise/infrastructure/database-postgres.md +400 -0
- package/expertise/infrastructure/devops-cicd.md +787 -0
- package/expertise/infrastructure/index.md +27 -0
- package/expertise/performance/PROGRESS.md +50 -0
- package/expertise/performance/backend/api-latency.md +1204 -0
- package/expertise/performance/backend/background-jobs.md +506 -0
- package/expertise/performance/backend/connection-pooling.md +1209 -0
- package/expertise/performance/backend/database-query-optimization.md +515 -0
- package/expertise/performance/backend/index.md +23 -0
- package/expertise/performance/backend/rate-limiting-and-throttling.md +971 -0
- package/expertise/performance/foundations/algorithmic-complexity.md +954 -0
- package/expertise/performance/foundations/caching-strategies.md +489 -0
- package/expertise/performance/foundations/concurrency-and-parallelism.md +847 -0
- package/expertise/performance/foundations/index.md +24 -0
- package/expertise/performance/foundations/measuring-and-profiling.md +440 -0
- package/expertise/performance/foundations/memory-management.md +964 -0
- package/expertise/performance/foundations/performance-budgets.md +1314 -0
- package/expertise/performance/index.md +31 -0
- package/expertise/performance/infrastructure/auto-scaling.md +1059 -0
- package/expertise/performance/infrastructure/cdn-and-edge.md +1081 -0
- package/expertise/performance/infrastructure/index.md +22 -0
- package/expertise/performance/infrastructure/load-balancing.md +1081 -0
- package/expertise/performance/infrastructure/observability.md +1079 -0
- package/expertise/performance/mobile/index.md +23 -0
- package/expertise/performance/mobile/mobile-animations.md +544 -0
- package/expertise/performance/mobile/mobile-memory-battery.md +416 -0
- package/expertise/performance/mobile/mobile-network.md +452 -0
- package/expertise/performance/mobile/mobile-rendering.md +599 -0
- package/expertise/performance/mobile/mobile-startup-time.md +505 -0
- package/expertise/performance/platform-specific/flutter-performance.md +647 -0
- package/expertise/performance/platform-specific/index.md +22 -0
- package/expertise/performance/platform-specific/node-performance.md +1307 -0
- package/expertise/performance/platform-specific/postgres-performance.md +1366 -0
- package/expertise/performance/platform-specific/react-performance.md +1403 -0
- package/expertise/performance/web/bundle-optimization.md +1239 -0
- package/expertise/performance/web/image-and-media.md +636 -0
- package/expertise/performance/web/index.md +24 -0
- package/expertise/performance/web/network-optimization.md +1133 -0
- package/expertise/performance/web/rendering-performance.md +1098 -0
- package/expertise/performance/web/ssr-and-hydration.md +918 -0
- package/expertise/performance/web/web-vitals.md +1374 -0
- package/expertise/quality/accessibility.md +985 -0
- package/expertise/quality/evidence-based-verification.md +499 -0
- package/expertise/quality/index.md +24 -0
- package/expertise/quality/ml-model-audit.md +614 -0
- package/expertise/quality/performance.md +600 -0
- package/expertise/quality/testing-api.md +891 -0
- package/expertise/quality/testing-mobile.md +496 -0
- package/expertise/quality/testing-web.md +849 -0
- package/expertise/security/PROGRESS.md +54 -0
- package/expertise/security/agentic-identity.md +540 -0
- package/expertise/security/compliance-frameworks.md +601 -0
- package/expertise/security/data/data-encryption.md +364 -0
- package/expertise/security/data/data-privacy-gdpr.md +692 -0
- package/expertise/security/data/database-security.md +1171 -0
- package/expertise/security/data/index.md +22 -0
- package/expertise/security/data/pii-handling.md +531 -0
- package/expertise/security/foundations/authentication.md +1041 -0
- package/expertise/security/foundations/authorization.md +603 -0
- package/expertise/security/foundations/cryptography.md +1001 -0
- package/expertise/security/foundations/index.md +25 -0
- package/expertise/security/foundations/owasp-top-10.md +1354 -0
- package/expertise/security/foundations/secrets-management.md +1217 -0
- package/expertise/security/foundations/secure-sdlc.md +700 -0
- package/expertise/security/foundations/supply-chain-security.md +698 -0
- package/expertise/security/index.md +31 -0
- package/expertise/security/infrastructure/cloud-security-aws.md +1296 -0
- package/expertise/security/infrastructure/cloud-security-gcp.md +1376 -0
- package/expertise/security/infrastructure/container-security.md +721 -0
- package/expertise/security/infrastructure/incident-response.md +1295 -0
- package/expertise/security/infrastructure/index.md +24 -0
- package/expertise/security/infrastructure/logging-and-monitoring.md +1618 -0
- package/expertise/security/infrastructure/network-security.md +1337 -0
- package/expertise/security/mobile/index.md +23 -0
- package/expertise/security/mobile/mobile-android-security.md +1218 -0
- package/expertise/security/mobile/mobile-binary-protection.md +1229 -0
- package/expertise/security/mobile/mobile-data-storage.md +1265 -0
- package/expertise/security/mobile/mobile-ios-security.md +1401 -0
- package/expertise/security/mobile/mobile-network-security.md +1520 -0
- package/expertise/security/smart-contract-security.md +594 -0
- package/expertise/security/testing/index.md +22 -0
- package/expertise/security/testing/penetration-testing.md +1258 -0
- package/expertise/security/testing/security-code-review.md +1765 -0
- package/expertise/security/testing/threat-modeling.md +1074 -0
- package/expertise/security/testing/vulnerability-scanning.md +1062 -0
- package/expertise/security/web/api-security.md +586 -0
- package/expertise/security/web/cors-and-headers.md +433 -0
- package/expertise/security/web/csrf.md +562 -0
- package/expertise/security/web/file-upload.md +1477 -0
- package/expertise/security/web/index.md +25 -0
- package/expertise/security/web/injection.md +1375 -0
- package/expertise/security/web/session-management.md +1101 -0
- package/expertise/security/web/xss.md +1158 -0
- package/exports/README.md +17 -0
- package/exports/hosts/claude/.claude/agents/clarifier.md +42 -0
- package/exports/hosts/claude/.claude/agents/content-author.md +63 -0
- package/exports/hosts/claude/.claude/agents/designer.md +55 -0
- package/exports/hosts/claude/.claude/agents/executor.md +55 -0
- package/exports/hosts/claude/.claude/agents/learner.md +51 -0
- package/exports/hosts/claude/.claude/agents/planner.md +53 -0
- package/exports/hosts/claude/.claude/agents/researcher.md +43 -0
- package/exports/hosts/claude/.claude/agents/reviewer.md +54 -0
- package/exports/hosts/claude/.claude/agents/specifier.md +47 -0
- package/exports/hosts/claude/.claude/agents/verifier.md +71 -0
- package/exports/hosts/claude/.claude/commands/author.md +42 -0
- package/exports/hosts/claude/.claude/commands/clarify.md +38 -0
- package/exports/hosts/claude/.claude/commands/design-review.md +46 -0
- package/exports/hosts/claude/.claude/commands/design.md +44 -0
- package/exports/hosts/claude/.claude/commands/discover.md +37 -0
- package/exports/hosts/claude/.claude/commands/execute.md +48 -0
- package/exports/hosts/claude/.claude/commands/learn.md +38 -0
- package/exports/hosts/claude/.claude/commands/plan-review.md +42 -0
- package/exports/hosts/claude/.claude/commands/plan.md +39 -0
- package/exports/hosts/claude/.claude/commands/prepare-next.md +37 -0
- package/exports/hosts/claude/.claude/commands/review.md +40 -0
- package/exports/hosts/claude/.claude/commands/run-audit.md +41 -0
- package/exports/hosts/claude/.claude/commands/spec-challenge.md +41 -0
- package/exports/hosts/claude/.claude/commands/specify.md +38 -0
- package/exports/hosts/claude/.claude/commands/verify.md +37 -0
- package/exports/hosts/claude/.claude/settings.json +34 -0
- package/exports/hosts/claude/CLAUDE.md +19 -0
- package/exports/hosts/claude/export.manifest.json +38 -0
- package/exports/hosts/claude/host-package.json +67 -0
- package/exports/hosts/codex/AGENTS.md +19 -0
- package/exports/hosts/codex/export.manifest.json +38 -0
- package/exports/hosts/codex/host-package.json +41 -0
- package/exports/hosts/cursor/.cursor/hooks.json +16 -0
- package/exports/hosts/cursor/.cursor/rules/wazir-core.mdc +19 -0
- package/exports/hosts/cursor/export.manifest.json +38 -0
- package/exports/hosts/cursor/host-package.json +42 -0
- package/exports/hosts/gemini/GEMINI.md +19 -0
- package/exports/hosts/gemini/export.manifest.json +38 -0
- package/exports/hosts/gemini/host-package.json +41 -0
- package/hooks/README.md +18 -0
- package/hooks/definitions/loop_cap_guard.yaml +21 -0
- package/hooks/definitions/post_tool_capture.yaml +24 -0
- package/hooks/definitions/pre_compact_summary.yaml +19 -0
- package/hooks/definitions/pre_tool_capture_route.yaml +19 -0
- package/hooks/definitions/protected_path_write_guard.yaml +19 -0
- package/hooks/definitions/session_start.yaml +19 -0
- package/hooks/definitions/stop_handoff_harvest.yaml +20 -0
- package/hooks/loop-cap-guard +17 -0
- package/hooks/post-tool-lint +36 -0
- package/hooks/protected-path-write-guard +17 -0
- package/hooks/session-start +41 -0
- package/llms-full.txt +2355 -0
- package/llms.txt +43 -0
- package/package.json +79 -0
- package/roles/README.md +20 -0
- package/roles/clarifier.md +42 -0
- package/roles/content-author.md +63 -0
- package/roles/designer.md +55 -0
- package/roles/executor.md +55 -0
- package/roles/learner.md +51 -0
- package/roles/planner.md +53 -0
- package/roles/researcher.md +43 -0
- package/roles/reviewer.md +54 -0
- package/roles/specifier.md +47 -0
- package/roles/verifier.md +71 -0
- package/schemas/README.md +24 -0
- package/schemas/accepted-learning.schema.json +20 -0
- package/schemas/author-artifact.schema.json +156 -0
- package/schemas/clarification.schema.json +19 -0
- package/schemas/design-artifact.schema.json +80 -0
- package/schemas/docs-claim.schema.json +18 -0
- package/schemas/export-manifest.schema.json +20 -0
- package/schemas/hook.schema.json +67 -0
- package/schemas/host-export-package.schema.json +18 -0
- package/schemas/implementation-plan.schema.json +19 -0
- package/schemas/proposed-learning.schema.json +19 -0
- package/schemas/research.schema.json +18 -0
- package/schemas/review.schema.json +29 -0
- package/schemas/run-manifest.schema.json +18 -0
- package/schemas/spec-challenge.schema.json +18 -0
- package/schemas/spec.schema.json +20 -0
- package/schemas/usage.schema.json +102 -0
- package/schemas/verification-proof.schema.json +29 -0
- package/schemas/wazir-manifest.schema.json +173 -0
- package/skills/README.md +40 -0
- package/skills/brainstorming/SKILL.md +77 -0
- package/skills/debugging/SKILL.md +50 -0
- package/skills/design/SKILL.md +61 -0
- package/skills/dispatching-parallel-agents/SKILL.md +128 -0
- package/skills/executing-plans/SKILL.md +70 -0
- package/skills/finishing-a-development-branch/SKILL.md +169 -0
- package/skills/humanize/SKILL.md +123 -0
- package/skills/init-pipeline/SKILL.md +124 -0
- package/skills/prepare-next/SKILL.md +20 -0
- package/skills/receiving-code-review/SKILL.md +123 -0
- package/skills/requesting-code-review/SKILL.md +105 -0
- package/skills/requesting-code-review/code-reviewer.md +108 -0
- package/skills/run-audit/SKILL.md +197 -0
- package/skills/scan-project/SKILL.md +41 -0
- package/skills/self-audit/SKILL.md +153 -0
- package/skills/subagent-driven-development/SKILL.md +154 -0
- package/skills/subagent-driven-development/code-quality-reviewer-prompt.md +26 -0
- package/skills/subagent-driven-development/implementer-prompt.md +102 -0
- package/skills/subagent-driven-development/spec-reviewer-prompt.md +61 -0
- package/skills/tdd/SKILL.md +23 -0
- package/skills/using-git-worktrees/SKILL.md +163 -0
- package/skills/using-skills/SKILL.md +95 -0
- package/skills/verification/SKILL.md +22 -0
- package/skills/wazir/SKILL.md +463 -0
- package/skills/writing-plans/SKILL.md +30 -0
- package/skills/writing-skills/SKILL.md +157 -0
- package/skills/writing-skills/anthropic-best-practices.md +122 -0
- package/skills/writing-skills/persuasion-principles.md +50 -0
- package/templates/README.md +20 -0
- package/templates/artifacts/README.md +10 -0
- package/templates/artifacts/accepted-learning.md +19 -0
- package/templates/artifacts/accepted-learning.template.json +12 -0
- package/templates/artifacts/author.md +74 -0
- package/templates/artifacts/author.template.json +19 -0
- package/templates/artifacts/clarification.md +21 -0
- package/templates/artifacts/clarification.template.json +12 -0
- package/templates/artifacts/execute-notes.md +19 -0
- package/templates/artifacts/implementation-plan.md +21 -0
- package/templates/artifacts/implementation-plan.template.json +11 -0
- package/templates/artifacts/learning-proposal.md +19 -0
- package/templates/artifacts/next-run-handoff.md +21 -0
- package/templates/artifacts/plan-review.md +19 -0
- package/templates/artifacts/proposed-learning.template.json +12 -0
- package/templates/artifacts/research.md +21 -0
- package/templates/artifacts/research.template.json +12 -0
- package/templates/artifacts/review-findings.md +19 -0
- package/templates/artifacts/review.template.json +11 -0
- package/templates/artifacts/run-manifest.template.json +8 -0
- package/templates/artifacts/spec-challenge.md +19 -0
- package/templates/artifacts/spec-challenge.template.json +11 -0
- package/templates/artifacts/spec.md +21 -0
- package/templates/artifacts/spec.template.json +12 -0
- package/templates/artifacts/verification-proof.md +19 -0
- package/templates/artifacts/verification-proof.template.json +11 -0
- package/templates/examples/accepted-learning.example.json +14 -0
- package/templates/examples/author.example.json +152 -0
- package/templates/examples/clarification.example.json +15 -0
- package/templates/examples/docs-claim.example.json +8 -0
- package/templates/examples/export-manifest.example.json +7 -0
- package/templates/examples/host-export-package.example.json +11 -0
- package/templates/examples/implementation-plan.example.json +17 -0
- package/templates/examples/proposed-learning.example.json +13 -0
- package/templates/examples/research.example.json +15 -0
- package/templates/examples/research.example.md +6 -0
- package/templates/examples/review.example.json +17 -0
- package/templates/examples/run-manifest.example.json +9 -0
- package/templates/examples/spec-challenge.example.json +14 -0
- package/templates/examples/spec.example.json +21 -0
- package/templates/examples/verification-proof.example.json +21 -0
- package/templates/examples/wazir-manifest.example.yaml +65 -0
- package/templates/task-definition-schema.md +99 -0
- package/tooling/README.md +20 -0
- package/tooling/src/adapters/context-mode.js +50 -0
- package/tooling/src/capture/command.js +376 -0
- package/tooling/src/capture/store.js +99 -0
- package/tooling/src/capture/usage.js +270 -0
- package/tooling/src/checks/branches.js +50 -0
- package/tooling/src/checks/brand-truth.js +110 -0
- package/tooling/src/checks/changelog.js +231 -0
- package/tooling/src/checks/command-registry.js +36 -0
- package/tooling/src/checks/commits.js +102 -0
- package/tooling/src/checks/docs-drift.js +103 -0
- package/tooling/src/checks/docs-truth.js +201 -0
- package/tooling/src/checks/runtime-surface.js +156 -0
- package/tooling/src/cli.js +116 -0
- package/tooling/src/command-options.js +56 -0
- package/tooling/src/commands/validate.js +320 -0
- package/tooling/src/doctor/command.js +91 -0
- package/tooling/src/export/command.js +77 -0
- package/tooling/src/export/compiler.js +498 -0
- package/tooling/src/guards/loop-cap-guard.js +52 -0
- package/tooling/src/guards/protected-path-write-guard.js +67 -0
- package/tooling/src/index/command.js +152 -0
- package/tooling/src/index/storage.js +1061 -0
- package/tooling/src/index/summarizers.js +261 -0
- package/tooling/src/loaders.js +18 -0
- package/tooling/src/project-root.js +22 -0
- package/tooling/src/recall/command.js +225 -0
- package/tooling/src/schema-validator.js +30 -0
- package/tooling/src/state-root.js +40 -0
- package/tooling/src/status/command.js +71 -0
- package/wazir.manifest.yaml +135 -0
- package/workflows/README.md +19 -0
- package/workflows/author.md +42 -0
- package/workflows/clarify.md +38 -0
- package/workflows/design-review.md +46 -0
- package/workflows/design.md +44 -0
- package/workflows/discover.md +37 -0
- package/workflows/execute.md +48 -0
- package/workflows/learn.md +38 -0
- package/workflows/plan-review.md +42 -0
- package/workflows/plan.md +39 -0
- package/workflows/prepare-next.md +37 -0
- package/workflows/review.md +40 -0
- package/workflows/run-audit.md +41 -0
- package/workflows/spec-challenge.md +41 -0
- package/workflows/specify.md +38 -0
- package/workflows/verify.md +37 -0
|
@@ -0,0 +1,853 @@
|
|
|
1
|
+
# Go -- Expertise Module
|
|
2
|
+
|
|
3
|
+
> A Go backend specialist designs, builds, and maintains server-side systems in Go --
|
|
4
|
+
> APIs, microservices, CLI tools, and data pipelines -- with emphasis on concurrency safety,
|
|
5
|
+
> operational simplicity, and production-grade reliability across the full service lifecycle.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 1. Core Patterns & Conventions
|
|
10
|
+
|
|
11
|
+
### Project Structure (Go 1.22+)
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
project-root/
|
|
15
|
+
cmd/
|
|
16
|
+
api/main.go # Binary entry points (one per deployable)
|
|
17
|
+
worker/main.go
|
|
18
|
+
internal/ # Private packages -- compiler-enforced import boundary
|
|
19
|
+
handler/ # HTTP/gRPC transport layer
|
|
20
|
+
service/ # Business logic
|
|
21
|
+
repository/ # Data access
|
|
22
|
+
model/ # Domain types
|
|
23
|
+
pkg/ # Public, reusable libraries (use sparingly)
|
|
24
|
+
api/ # OpenAPI specs, protobuf definitions
|
|
25
|
+
migrations/ # SQL migration files
|
|
26
|
+
scripts/ # Build/deploy helpers
|
|
27
|
+
go.mod
|
|
28
|
+
go.sum
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**Key rules:**
|
|
32
|
+
- `internal/` is compiler-enforced: code inside cannot be imported by external modules.
|
|
33
|
+
- Keep `cmd/` thin -- parse config, wire dependencies, call `internal/`.
|
|
34
|
+
- Avoid a `pkg/` directory unless you genuinely intend code to be imported by other modules.
|
|
35
|
+
The Go team does not endorse `golang-standards/project-layout` as official (ref: Russ Cox,
|
|
36
|
+
Go issue #45861). Start flat, add structure when complexity demands it.
|
|
37
|
+
|
|
38
|
+
### Naming Conventions
|
|
39
|
+
|
|
40
|
+
| Rule | Example | Anti-example |
|
|
41
|
+
|------|---------|--------------|
|
|
42
|
+
| Exported = PascalCase | `func NewServer()` | `func new_server()` |
|
|
43
|
+
| Unexported = camelCase | `var connPool` | `var conn_pool` |
|
|
44
|
+
| Package names: short, lowercase, singular | `package user` | `package userService` |
|
|
45
|
+
| Acronyms fully capitalized | `HTTPClient`, `ID` | `HttpClient`, `Id` |
|
|
46
|
+
| Interfaces: verb+er for single-method | `type Reader interface` | `type IReader interface` |
|
|
47
|
+
| Getters omit "Get" prefix | `func (u *User) Name()` | `func (u *User) GetName()` |
|
|
48
|
+
|
|
49
|
+
Source: Effective Go (https://go.dev/doc/effective_go)
|
|
50
|
+
|
|
51
|
+
### Architecture Patterns
|
|
52
|
+
|
|
53
|
+
- **Flat structure** -- best for small services (<10 files). All Go files in root package.
|
|
54
|
+
- **Layered (handler/service/repository)** -- most common for mid-size APIs. Clean dependency flow: handler -> service -> repository.
|
|
55
|
+
- **Hexagonal / Ports-and-Adapters** -- define domain interfaces in `internal/domain/`, implement adapters in `internal/adapter/`. Best for complex domains or when multiple transports (HTTP + gRPC) coexist.
|
|
56
|
+
- **Clean Architecture** -- similar to hexagonal but with explicit use-case interactors. Use when business rules need rigorous isolation from infrastructure.
|
|
57
|
+
|
|
58
|
+
### HTTP Frameworks
|
|
59
|
+
|
|
60
|
+
**stdlib net/http (Go 1.22+)** -- now supports method-based routing and path parameters:
|
|
61
|
+
|
|
62
|
+
```go
|
|
63
|
+
mux := http.NewServeMux()
|
|
64
|
+
mux.HandleFunc("GET /users/{id}", getUser) // Method + path param
|
|
65
|
+
mux.HandleFunc("POST /users", createUser)
|
|
66
|
+
mux.HandleFunc("GET /files/{path...}", serveFile) // Wildcard catch-all
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`r.PathValue("id")` retrieves the matched segment. This eliminates the need for a
|
|
70
|
+
third-party router in many projects.
|
|
71
|
+
|
|
72
|
+
**Chi** -- net/http compatible, composable middleware, grouped routes. Best choice when you
|
|
73
|
+
want enhanced routing but stay close to stdlib patterns. All standard `http.Handler`
|
|
74
|
+
middleware works without modification.
|
|
75
|
+
|
|
76
|
+
**Gin** -- highest raw throughput in benchmarks, large ecosystem. Uses its own `gin.Context`
|
|
77
|
+
(not `context.Context`), which couples your handlers to the framework.
|
|
78
|
+
|
|
79
|
+
**Echo** -- clean API, returns errors from handlers (instead of panic), built-in support for
|
|
80
|
+
file serving, WebSocket, and HTTP/2. Uses standard `context.Context`.
|
|
81
|
+
|
|
82
|
+
### Concurrency Patterns
|
|
83
|
+
|
|
84
|
+
**Goroutines + channels** -- Go's primary concurrency primitives.
|
|
85
|
+
|
|
86
|
+
```go
|
|
87
|
+
// Fan-out / fan-in with errgroup (golang.org/x/sync/errgroup)
|
|
88
|
+
g, ctx := errgroup.WithContext(ctx)
|
|
89
|
+
for _, url := range urls {
|
|
90
|
+
g.Go(func() error {
|
|
91
|
+
return fetch(ctx, url)
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
if err := g.Wait(); err != nil {
|
|
95
|
+
// first error cancels ctx, all goroutines wind down
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**When to use channels vs. mutexes:**
|
|
100
|
+
- Channels: data flows between goroutines, pipeline stages, fan-out/fan-in, signaling.
|
|
101
|
+
- `sync.Mutex`: protecting shared state (counters, caches, maps). Simpler, lower overhead.
|
|
102
|
+
- `sync.RWMutex`: multiple concurrent readers, exclusive writer.
|
|
103
|
+
- `sync.Once`: one-time initialization (lazy singletons).
|
|
104
|
+
- `sync.Pool`: reuse temporary objects to reduce GC pressure.
|
|
105
|
+
|
|
106
|
+
**Context propagation:**
|
|
107
|
+
- Every function doing I/O or long work should accept `context.Context` as its first parameter.
|
|
108
|
+
- Use `context.WithTimeout` or `context.WithDeadline` for every external call (DB, HTTP, gRPC).
|
|
109
|
+
- Never store contexts in structs; pass them explicitly.
|
|
110
|
+
|
|
111
|
+
### Error Handling
|
|
112
|
+
|
|
113
|
+
```go
|
|
114
|
+
// Sentinel errors -- package-level, for well-known conditions
|
|
115
|
+
var ErrNotFound = errors.New("resource not found")
|
|
116
|
+
|
|
117
|
+
// Error wrapping -- add context with %w verb
|
|
118
|
+
if err != nil {
|
|
119
|
+
return fmt.Errorf("loading user %d: %w", id, err)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Custom error types -- when callers need structured data
|
|
123
|
+
type ValidationError struct {
|
|
124
|
+
Field string
|
|
125
|
+
Message string
|
|
126
|
+
}
|
|
127
|
+
func (e *ValidationError) Error() string {
|
|
128
|
+
return fmt.Sprintf("validation: %s: %s", e.Field, e.Message)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Inspection -- always use errors.Is / errors.As (not == or type assertion)
|
|
132
|
+
if errors.Is(err, ErrNotFound) { ... }
|
|
133
|
+
var ve *ValidationError
|
|
134
|
+
if errors.As(err, &ve) { ... }
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**Rules:**
|
|
138
|
+
- Wrap errors at domain boundaries to add context; do not wrap at every call site.
|
|
139
|
+
- Sentinel errors are for conditions callers must match on (e.g., `sql.ErrNoRows`).
|
|
140
|
+
- Return `error` as the last return value -- never panic for expected failures.
|
|
141
|
+
|
|
142
|
+
### Interface Design
|
|
143
|
+
|
|
144
|
+
- **Accept interfaces, return structs.** Callers define the interface they need.
|
|
145
|
+
- Keep interfaces small (1-3 methods). The larger the interface, the weaker the abstraction.
|
|
146
|
+
- Define interfaces where they are consumed, not where they are implemented.
|
|
147
|
+
- Standard library models: `io.Reader`, `io.Writer`, `fmt.Stringer`.
|
|
148
|
+
|
|
149
|
+
### Logging & Observability
|
|
150
|
+
|
|
151
|
+
**log/slog (Go 1.21+, stdlib)** -- structured, leveled logging with JSON or text output:
|
|
152
|
+
|
|
153
|
+
```go
|
|
154
|
+
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
|
|
155
|
+
Level: slog.LevelInfo,
|
|
156
|
+
}))
|
|
157
|
+
logger.Info("request handled",
|
|
158
|
+
slog.String("method", r.Method),
|
|
159
|
+
slog.Int("status", code),
|
|
160
|
+
slog.Duration("latency", elapsed),
|
|
161
|
+
)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
- **zerolog** -- zero-allocation JSON logger. Use when slog overhead matters at >50k logs/sec.
|
|
165
|
+
- **OpenTelemetry** -- integrate via `otelslog` bridge (`go.opentelemetry.io/contrib/bridges/otelslog`)
|
|
166
|
+
to inject trace ID and span ID into log records automatically. Adds <1% overhead.
|
|
167
|
+
- Be consistent with key names (`request_id`, not `requestId`). Enforce naming conventions.
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## 2. Anti-Patterns & Pitfalls
|
|
172
|
+
|
|
173
|
+
### 1. Goroutine leaks
|
|
174
|
+
**Why it matters:** Leaked goroutines consume memory and CPU forever. Common cause: sending to
|
|
175
|
+
a channel that no one reads, or forgetting to cancel a context. Always use `errgroup` or
|
|
176
|
+
explicit cancellation.
|
|
177
|
+
|
|
178
|
+
### 2. Closing a channel from the receiver side
|
|
179
|
+
**Why it matters:** Only the sender should close a channel. Closing from the receiver can cause
|
|
180
|
+
a panic if the sender writes to the closed channel. If multiple senders exist, use `sync.Once`
|
|
181
|
+
or coordinate via a done channel.
|
|
182
|
+
|
|
183
|
+
### 3. Ignoring errors
|
|
184
|
+
**Why it matters:** `_ = doSomething()` silently swallows failures. In production, this leads to
|
|
185
|
+
data corruption or silent degradation. Always handle or explicitly document why an error is
|
|
186
|
+
discarded.
|
|
187
|
+
|
|
188
|
+
### 4. Using `init()` for complex logic
|
|
189
|
+
**Why it matters:** `init()` runs at import time, before `main()`. Side effects (DB connections,
|
|
190
|
+
HTTP calls) inside `init()` make code untestable, create hidden dependencies, and cause
|
|
191
|
+
unpredictable startup failures.
|
|
192
|
+
|
|
193
|
+
### 5. Nil map writes
|
|
194
|
+
**Why it matters:** Writing to a nil map panics at runtime. Always initialize maps with `make()`
|
|
195
|
+
before writing, or use `var m = map[K]V{}`.
|
|
196
|
+
|
|
197
|
+
### 6. Variable shadowing with `:=`
|
|
198
|
+
**Why it matters:** Redeclaring a variable with `:=` in an inner scope creates a new variable,
|
|
199
|
+
leaving the outer one unchanged. This causes subtle bugs, especially with `err`.
|
|
200
|
+
|
|
201
|
+
### 7. Misusing `sync.WaitGroup` (Add inside goroutine)
|
|
202
|
+
**Why it matters:** If `wg.Add(1)` is called inside the goroutine instead of before `go func()`,
|
|
203
|
+
`wg.Wait()` may return before the goroutine starts. Always call `Add` before launching.
|
|
204
|
+
|
|
205
|
+
### 8. Not using `defer` for cleanup
|
|
206
|
+
**Why it matters:** Manual cleanup before every `return` is error-prone. `defer` guarantees
|
|
207
|
+
execution even on panics. Use it for closing files, releasing locks, and rolling back
|
|
208
|
+
transactions.
|
|
209
|
+
|
|
210
|
+
### 9. Slice append surprises
|
|
211
|
+
**Why it matters:** `append()` may or may not allocate a new backing array. Passing a slice to
|
|
212
|
+
a function and appending can modify the caller's data unexpectedly. Use `slices.Clone()` (Go
|
|
213
|
+
1.21+) or explicit copy when you need independence.
|
|
214
|
+
|
|
215
|
+
### 10. Over-using `interface{}` / `any`
|
|
216
|
+
**Why it matters:** Bypasses the type system. You lose compile-time safety and force runtime
|
|
217
|
+
type assertions everywhere. With generics (Go 1.18+), use type parameters instead.
|
|
218
|
+
|
|
219
|
+
### 11. Creating utility packages (utils/, helpers/, common/)
|
|
220
|
+
**Why it matters:** These become dumping grounds with no cohesion. Name packages by what they
|
|
221
|
+
provide (`auth`, `cache`, `retry`), not how they are used.
|
|
222
|
+
|
|
223
|
+
### 12. Blocking the main goroutine accidentally
|
|
224
|
+
**Why it matters:** If `main()` returns, all goroutines are killed instantly -- no cleanup, no
|
|
225
|
+
graceful shutdown. Use `signal.NotifyContext` and `server.Shutdown(ctx)` for clean exits.
|
|
226
|
+
|
|
227
|
+
### 13. Unbounded goroutine creation
|
|
228
|
+
**Why it matters:** Spawning a goroutine per request without limits (e.g., `for range requests { go handle(r) }`) can exhaust memory under load. Use worker pools or `semaphore.Weighted`.
|
|
229
|
+
|
|
230
|
+
### 14. Data races on maps
|
|
231
|
+
**Why it matters:** Maps in Go are not safe for concurrent use. Concurrent read+write without
|
|
232
|
+
a mutex causes runtime crashes. Use `sync.RWMutex` or `sync.Map` (for specific patterns only).
|
|
233
|
+
|
|
234
|
+
Sources: "100 Go Mistakes and How to Avoid Them" by Teiva Harsanyi (https://100go.co/),
|
|
235
|
+
Effective Go (https://go.dev/doc/effective_go)
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## 3. Testing Strategy
|
|
240
|
+
|
|
241
|
+
### Table-Driven Tests
|
|
242
|
+
|
|
243
|
+
```go
|
|
244
|
+
func TestParseAge(t *testing.T) {
|
|
245
|
+
tests := []struct {
|
|
246
|
+
name string
|
|
247
|
+
input string
|
|
248
|
+
want int
|
|
249
|
+
wantErr bool
|
|
250
|
+
}{
|
|
251
|
+
{name: "valid", input: "25", want: 25},
|
|
252
|
+
{name: "negative", input: "-1", wantErr: true},
|
|
253
|
+
{name: "non-numeric", input: "abc", wantErr: true},
|
|
254
|
+
{name: "empty", input: "", wantErr: true},
|
|
255
|
+
}
|
|
256
|
+
for _, tt := range tests {
|
|
257
|
+
t.Run(tt.name, func(t *testing.T) {
|
|
258
|
+
got, err := ParseAge(tt.input)
|
|
259
|
+
if (err != nil) != tt.wantErr {
|
|
260
|
+
t.Fatalf("ParseAge(%q) err = %v, wantErr %v", tt.input, err, tt.wantErr)
|
|
261
|
+
}
|
|
262
|
+
if got != tt.want {
|
|
263
|
+
t.Errorf("ParseAge(%q) = %d, want %d", tt.input, got, tt.want)
|
|
264
|
+
}
|
|
265
|
+
})
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### Testify vs. stdlib
|
|
271
|
+
|
|
272
|
+
- **stdlib `testing`** -- sufficient for most projects. Zero dependencies.
|
|
273
|
+
Use `t.Errorf` (continue) vs. `t.Fatalf` (stop) deliberately.
|
|
274
|
+
- **testify/assert** -- adds `assert.Equal`, `assert.NoError` for readable assertions.
|
|
275
|
+
Adds a dependency but widely adopted. Use `require` (fatal) for preconditions,
|
|
276
|
+
`assert` (non-fatal) for the rest.
|
|
277
|
+
|
|
278
|
+
### Integration Testing
|
|
279
|
+
|
|
280
|
+
- Use `TestMain(m *testing.M)` to set up/teardown shared resources (DB, containers).
|
|
281
|
+
- Use `testcontainers-go` to spin up real Postgres/Redis/Kafka in tests.
|
|
282
|
+
- Use build tags (`//go:build integration`) to separate integration from unit tests.
|
|
283
|
+
- Run with: `go test -tags=integration -count=1 ./...`
|
|
284
|
+
|
|
285
|
+
### Mocking
|
|
286
|
+
|
|
287
|
+
- **Interface-based mocking** -- define a small interface, implement a mock struct in
|
|
288
|
+
`_test.go`. No library needed for simple cases.
|
|
289
|
+
- **testify/mock** -- generates mock expectations with `On` / `Return` / `AssertExpectations`.
|
|
290
|
+
- **gomock** -- code-generated mocks via `mockgen`. More strict, better for large interfaces.
|
|
291
|
+
- **Prefer fakes over mocks** for repositories -- in-memory implementations are often
|
|
292
|
+
clearer and catch more bugs than mock expectation chains.
|
|
293
|
+
|
|
294
|
+
### Benchmarking
|
|
295
|
+
|
|
296
|
+
```go
|
|
297
|
+
func BenchmarkHash(b *testing.B) {
|
|
298
|
+
data := []byte("benchmark payload")
|
|
299
|
+
b.ResetTimer()
|
|
300
|
+
for b.Loop() { // Go 1.24+: b.Loop() replaces manual b.N loop
|
|
301
|
+
sha256.Sum256(data)
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
// Run: go test -bench=BenchmarkHash -benchmem ./...
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
- Use `b.ReportAllocs()` to surface allocations per operation.
|
|
308
|
+
- Use `benchstat` to compare results across runs with statistical rigor.
|
|
309
|
+
|
|
310
|
+
### Fuzzing (Go 1.18+)
|
|
311
|
+
|
|
312
|
+
```go
|
|
313
|
+
func FuzzParseJSON(f *testing.F) {
|
|
314
|
+
f.Add([]byte(`{"name":"test"}`)) // Seed corpus
|
|
315
|
+
f.Fuzz(func(t *testing.T, data []byte) {
|
|
316
|
+
var result map[string]any
|
|
317
|
+
_ = json.Unmarshal(data, &result) // Must not panic
|
|
318
|
+
})
|
|
319
|
+
}
|
|
320
|
+
// Run: go test -fuzz=FuzzParseJSON -fuzztime=30s ./...
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
- Fuzzing finds panics, crashes, and edge cases humans miss.
|
|
324
|
+
- Seed corpus entries in `testdata/fuzz/<FuncName>/` persist across runs.
|
|
325
|
+
- Particularly valuable for parsers, validators, and security-sensitive code.
|
|
326
|
+
|
|
327
|
+
### Test Organization
|
|
328
|
+
|
|
329
|
+
- Test files: `foo_test.go` alongside `foo.go` in the same package.
|
|
330
|
+
- Black-box tests: use `package foo_test` to test only the exported API.
|
|
331
|
+
- White-box tests: use `package foo` when you need access to internals.
|
|
332
|
+
- Test helpers: use `t.Helper()` to clean up stack traces.
|
|
333
|
+
|
|
334
|
+
---
|
|
335
|
+
|
|
336
|
+
## 4. Performance Considerations
|
|
337
|
+
|
|
338
|
+
### Goroutine & Memory Management
|
|
339
|
+
|
|
340
|
+
- Goroutines start at ~2-4 KB stack. Creating millions is feasible but not free.
|
|
341
|
+
- Use `semaphore.Weighted` or worker pools to bound concurrency under load.
|
|
342
|
+
- Avoid allocating in hot loops -- pre-allocate slices with `make([]T, 0, capacity)`.
|
|
343
|
+
- Use `sync.Pool` for frequently allocated/freed objects (buffers, temp structs).
|
|
344
|
+
|
|
345
|
+
### Profiling with pprof
|
|
346
|
+
|
|
347
|
+
```go
|
|
348
|
+
import _ "net/http/pprof" // Register pprof handlers
|
|
349
|
+
|
|
350
|
+
go func() {
|
|
351
|
+
log.Println(http.ListenAndServe("localhost:6060", nil))
|
|
352
|
+
}()
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
Profile types:
|
|
356
|
+
- **CPU**: `go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30`
|
|
357
|
+
- **Heap**: `go tool pprof http://localhost:6060/debug/pprof/heap`
|
|
358
|
+
- **Goroutine**: `go tool pprof http://localhost:6060/debug/pprof/goroutine`
|
|
359
|
+
- **Mutex contention**: `go tool pprof http://localhost:6060/debug/pprof/mutex`
|
|
360
|
+
|
|
361
|
+
Visualize with: `go tool pprof -http=:8080 profile.pb.gz`
|
|
362
|
+
|
|
363
|
+
### Allocation Reduction
|
|
364
|
+
|
|
365
|
+
- Use `strings.Builder` instead of `+` concatenation in loops.
|
|
366
|
+
- Return values by value (not pointer) for small structs -- keeps them on the stack.
|
|
367
|
+
- Avoid `fmt.Sprintf` in hot paths; use `strconv` functions directly.
|
|
368
|
+
- Use `slices.Grow()` (Go 1.21+) to pre-extend slice capacity.
|
|
369
|
+
- Check escape analysis: `go build -gcflags='-m' ./...`
|
|
370
|
+
|
|
371
|
+
### Connection Pooling
|
|
372
|
+
|
|
373
|
+
- `database/sql` has built-in pooling: configure `SetMaxOpenConns`, `SetMaxIdleConns`,
|
|
374
|
+
`SetConnMaxLifetime`, `SetConnMaxIdleTime`.
|
|
375
|
+
- `http.Client` reuses connections by default via `http.Transport`. Set
|
|
376
|
+
`MaxIdleConnsPerHost` to match expected parallelism.
|
|
377
|
+
- pgx v5 provides its own pool via `pgxpool.New()` -- preferred over `database/sql`
|
|
378
|
+
pooling for PostgreSQL.
|
|
379
|
+
|
|
380
|
+
### GC Tuning
|
|
381
|
+
|
|
382
|
+
- **GOGC=100** (default): GC triggers when live heap doubles. Increase (e.g., 200)
|
|
383
|
+
to trade memory for less CPU spent on GC. Decrease (e.g., 50) for lower memory use.
|
|
384
|
+
- **GOMEMLIMIT** (Go 1.19+): Sets a soft memory ceiling (e.g., `GOMEMLIMIT=2GiB`).
|
|
385
|
+
The GC becomes more aggressive as usage approaches the limit. Prevents OOM kills in
|
|
386
|
+
containers. Recommended over tuning GOGC alone.
|
|
387
|
+
- **Profile before tuning.** Use pprof heap profiles to confirm GC is the bottleneck.
|
|
388
|
+
- Go 1.24 introduces Swiss Tables for built-in maps -- measurably faster for
|
|
389
|
+
map-heavy workloads with no code changes.
|
|
390
|
+
|
|
391
|
+
Source: Go GC Guide (https://go.dev/doc/gc-guide)
|
|
392
|
+
|
|
393
|
+
---
|
|
394
|
+
|
|
395
|
+
## 5. Security Considerations
|
|
396
|
+
|
|
397
|
+
### Input Validation
|
|
398
|
+
|
|
399
|
+
- Validate all user input at the handler layer before passing to services.
|
|
400
|
+
- Use `strconv.Atoi` / `strconv.ParseInt` for numeric conversion -- never `fmt.Sscanf`.
|
|
401
|
+
- Limit request body size: `http.MaxBytesReader(w, r.Body, 1<<20)` (1 MB).
|
|
402
|
+
- Use a validation library (`go-playground/validator`) for struct tag-based validation.
|
|
403
|
+
|
|
404
|
+
### SQL Injection Prevention
|
|
405
|
+
|
|
406
|
+
```go
|
|
407
|
+
// SAFE: parameterized query -- arguments sent separately from SQL
|
|
408
|
+
row := db.QueryRowContext(ctx, "SELECT name FROM users WHERE id = $1", userID)
|
|
409
|
+
|
|
410
|
+
// UNSAFE: string interpolation -- SQL injection vector
|
|
411
|
+
query := fmt.Sprintf("SELECT name FROM users WHERE id = %s", userID) // NEVER
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
- Always use parameterized queries (`$1`, `?` placeholders).
|
|
415
|
+
- `database/sql` automatically uses prepared statements.
|
|
416
|
+
- ORMs (GORM, ent) and code generators (sqlc) parameterize by default.
|
|
417
|
+
|
|
418
|
+
Source: Go docs -- "Avoiding SQL injection risk" (https://go.dev/doc/database/sql-injection)
|
|
419
|
+
|
|
420
|
+
### Crypto Best Practices
|
|
421
|
+
|
|
422
|
+
- Use `crypto/rand` for random values (not `math/rand`).
|
|
423
|
+
- Use `golang.org/x/crypto/bcrypt` for password hashing (cost >= 12).
|
|
424
|
+
- Use `crypto/subtle.ConstantTimeCompare` for token/HMAC comparison.
|
|
425
|
+
- Go 1.24 adds FIPS 140-3 compliance support, `crypto/mlkem`, `crypto/hkdf`,
|
|
426
|
+
`crypto/pbkdf2`, and `crypto/sha3` as stdlib packages.
|
|
427
|
+
|
|
428
|
+
### TLS Configuration
|
|
429
|
+
|
|
430
|
+
```go
|
|
431
|
+
tlsConfig := &tls.Config{
|
|
432
|
+
MinVersion: tls.VersionTLS12, // Never allow TLS 1.0/1.1
|
|
433
|
+
CipherSuites: nil, // Let Go choose secure defaults
|
|
434
|
+
PreferServerCipherSuites: true,
|
|
435
|
+
}
|
|
436
|
+
server := &http.Server{
|
|
437
|
+
TLSConfig: tlsConfig,
|
|
438
|
+
ReadTimeout: 5 * time.Second,
|
|
439
|
+
WriteTimeout: 10 * time.Second,
|
|
440
|
+
IdleTimeout: 120 * time.Second,
|
|
441
|
+
}
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
- Always set `ReadTimeout`, `WriteTimeout`, `IdleTimeout` to prevent slowloris attacks.
|
|
445
|
+
- Use HSTS headers: `Strict-Transport-Security: max-age=63072000; includeSubDomains`.
|
|
446
|
+
|
|
447
|
+
### CORS & Middleware Security
|
|
448
|
+
|
|
449
|
+
- Use `github.com/rs/cors` for CORS handling -- configure explicit allowed origins,
|
|
450
|
+
methods, and headers. Never use `AllowAll()` in production.
|
|
451
|
+
- Add security headers via middleware: `X-Content-Type-Options: nosniff`,
|
|
452
|
+
`X-Frame-Options: DENY`, `Content-Security-Policy`.
|
|
453
|
+
- Rate-limit endpoints with `golang.org/x/time/rate` or middleware like
|
|
454
|
+
`github.com/ulule/limiter`.
|
|
455
|
+
|
|
456
|
+
---
|
|
457
|
+
|
|
458
|
+
## 6. Integration Patterns
|
|
459
|
+
|
|
460
|
+
### Database
|
|
461
|
+
|
|
462
|
+
**database/sql (stdlib)** -- universal interface, driver-agnostic. Good for simple use cases
|
|
463
|
+
or when you need MySQL + Postgres support.
|
|
464
|
+
|
|
465
|
+
**pgx v5** -- PostgreSQL-native driver. 30-50% faster than database/sql for Postgres.
|
|
466
|
+
Supports COPY, LISTEN/NOTIFY, custom types, batch queries. Use `pgxpool` for connection
|
|
467
|
+
pooling.
|
|
468
|
+
|
|
469
|
+
**sqlc** -- write SQL, generate type-safe Go code. Zero runtime overhead. Ideal for teams
|
|
470
|
+
comfortable with SQL who want compile-time safety without an ORM. Supports PostgreSQL,
|
|
471
|
+
MySQL, SQLite.
|
|
472
|
+
|
|
473
|
+
**GORM** -- full ORM with auto-migration, associations, hooks. Highest developer velocity
|
|
474
|
+
for CRUD-heavy apps. Performance overhead vs. raw SQL (~20-40% slower). GORM v2 adds
|
|
475
|
+
modularity and plugin system.
|
|
476
|
+
|
|
477
|
+
**ent** -- code-first ORM by Meta. Schema defined in Go code, generates type-safe API.
|
|
478
|
+
Strong for complex graph-like data models. Static typing catches errors at compile time.
|
|
479
|
+
|
|
480
|
+
### Message Queues
|
|
481
|
+
|
|
482
|
+
**NATS** -- lightweight, high-performance. Built-in pub/sub, request-reply, queue groups.
|
|
483
|
+
JetStream adds persistence and exactly-once delivery. Best for microservice communication.
|
|
484
|
+
Go client: `github.com/nats-io/nats.go`.
|
|
485
|
+
|
|
486
|
+
**Kafka** (via `github.com/segmentio/kafka-go` or `confluent-kafka-go`) -- distributed
|
|
487
|
+
event streaming. Use for high-throughput event sourcing, audit logs, cross-service data
|
|
488
|
+
pipelines. Partition-based parallelism.
|
|
489
|
+
|
|
490
|
+
**RabbitMQ** (via `github.com/rabbitmq/amqp091-go`) -- traditional message broker with
|
|
491
|
+
routing, dead-letter queues, and acknowledgments. Best for task queues and workflow
|
|
492
|
+
orchestration.
|
|
493
|
+
|
|
494
|
+
### gRPC with Protobuf
|
|
495
|
+
|
|
496
|
+
```protobuf
|
|
497
|
+
// user.proto
|
|
498
|
+
service UserService {
|
|
499
|
+
rpc GetUser(GetUserRequest) returns (User);
|
|
500
|
+
rpc ListUsers(ListUsersRequest) returns (stream User);
|
|
501
|
+
}
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
- Use `buf` (buf.build) for protobuf management over raw `protoc`.
|
|
505
|
+
- Implement `UnaryInterceptor` / `StreamInterceptor` for logging, auth, metrics.
|
|
506
|
+
- Use `grpc-gateway` to expose gRPC services as REST APIs simultaneously.
|
|
507
|
+
- Always set deadlines on gRPC calls via context.
|
|
508
|
+
|
|
509
|
+
### REST API Design
|
|
510
|
+
|
|
511
|
+
- Use plural nouns for resources: `/users`, `/orders/{id}`.
|
|
512
|
+
- Return appropriate HTTP status codes (201 Created, 204 No Content, 404, 422).
|
|
513
|
+
- Use `encoding/json` with struct tags: `json:"name,omitempty"`.
|
|
514
|
+
- Implement pagination with cursor-based tokens (not offset-based) for large datasets.
|
|
515
|
+
- Version APIs via URL path (`/v1/users`) or `Accept` header.
|
|
516
|
+
|
|
517
|
+
### File Handling
|
|
518
|
+
|
|
519
|
+
- Use `os.Root` (Go 1.24+) to restrict filesystem operations to a specific directory,
|
|
520
|
+
preventing path traversal attacks.
|
|
521
|
+
- Use `io.LimitReader` to prevent unbounded reads.
|
|
522
|
+
- For uploads, stream to storage (S3, GCS) directly rather than buffering in memory.
|
|
523
|
+
|
|
524
|
+
---
|
|
525
|
+
|
|
526
|
+
## 7. DevOps & Deployment
|
|
527
|
+
|
|
528
|
+
### Build
|
|
529
|
+
|
|
530
|
+
```bash
|
|
531
|
+
# Production binary -- static, stripped, with version info
|
|
532
|
+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
|
|
533
|
+
-ldflags="-s -w -X main.version=$(git describe --tags)" \
|
|
534
|
+
-o bin/api ./cmd/api
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
- `CGO_ENABLED=0`: static binary, no libc dependency. Required for scratch/distroless.
|
|
538
|
+
- `-ldflags="-s -w"`: strip debug info and symbol table (~30% smaller binary).
|
|
539
|
+
- `-X main.version=...`: inject build-time variables.
|
|
540
|
+
- Go 1.24: `tool` directive in `go.mod` tracks executable dependencies (replaces
|
|
541
|
+
`tools.go` blank-import hack).
|
|
542
|
+
|
|
543
|
+
### Docker (Multi-Stage)
|
|
544
|
+
|
|
545
|
+
```dockerfile
|
|
546
|
+
# Build stage
|
|
547
|
+
FROM golang:1.24-alpine AS builder
|
|
548
|
+
WORKDIR /app
|
|
549
|
+
COPY go.mod go.sum ./
|
|
550
|
+
RUN go mod download
|
|
551
|
+
COPY . .
|
|
552
|
+
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /api ./cmd/api
|
|
553
|
+
|
|
554
|
+
# Runtime stage
|
|
555
|
+
FROM gcr.io/distroless/static-debian12:nonroot
|
|
556
|
+
COPY --from=builder /api /api
|
|
557
|
+
EXPOSE 8080
|
|
558
|
+
ENTRYPOINT ["/api"]
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
- **scratch**: smallest possible (just your binary). No CA certs, no timezone data.
|
|
562
|
+
Must embed or copy them manually.
|
|
563
|
+
- **distroless/static**: ~2 MB. Includes CA certs, timezone data, no shell.
|
|
564
|
+
Preferred for production.
|
|
565
|
+
- **Alpine**: ~5 MB. Has shell for debugging. Good for staging.
|
|
566
|
+
- Run as non-root: `USER nonroot:nonroot` or use distroless `nonroot` tag.
|
|
567
|
+
- Typical final image: 10-20 MB (vs. 800+ MB with full golang base).
|
|
568
|
+
|
|
569
|
+
### CI/CD
|
|
570
|
+
|
|
571
|
+
```yaml
|
|
572
|
+
# Essential CI checks (GitHub Actions example)
|
|
573
|
+
steps:
|
|
574
|
+
- run: go vet ./... # Built-in static analysis
|
|
575
|
+
- run: golangci-lint run --timeout 5m # Meta-linter (40+ linters)
|
|
576
|
+
- run: go test -race -coverprofile=cover.out ./... # Tests + race detector
|
|
577
|
+
- run: go test -tags=integration ./... # Integration tests
|
|
578
|
+
- run: govulncheck ./... # Known vulnerability scan
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
- **golangci-lint** -- runs staticcheck, gosec, errcheck, gocritic, and 40+ others
|
|
582
|
+
in a single pass. Configure via `.golangci.yml`.
|
|
583
|
+
- **govulncheck** -- official Go vulnerability scanner (golang.org/x/vuln/cmd/govulncheck).
|
|
584
|
+
- **-race flag** -- enables race detector. Always run in CI; catches data races.
|
|
585
|
+
- **-count=1** -- disables test caching for integration tests.
|
|
586
|
+
|
|
587
|
+
### Cross-Compilation
|
|
588
|
+
|
|
589
|
+
```bash
|
|
590
|
+
# Build for multiple targets
|
|
591
|
+
GOOS=linux GOARCH=amd64 go build -o bin/api-linux-amd64 ./cmd/api
|
|
592
|
+
GOOS=linux GOARCH=arm64 go build -o bin/api-linux-arm64 ./cmd/api
|
|
593
|
+
GOOS=darwin GOARCH=arm64 go build -o bin/api-darwin-arm64 ./cmd/api
|
|
594
|
+
GOOS=windows GOARCH=amd64 go build -o bin/api-windows.exe ./cmd/api
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
Go cross-compiles natively -- no toolchain setup needed (when CGO_ENABLED=0).
|
|
598
|
+
|
|
599
|
+
### Monitoring
|
|
600
|
+
|
|
601
|
+
```go
|
|
602
|
+
import (
|
|
603
|
+
"github.com/prometheus/client_golang/prometheus"
|
|
604
|
+
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
605
|
+
)
|
|
606
|
+
|
|
607
|
+
var requestDuration = prometheus.NewHistogramVec(
|
|
608
|
+
prometheus.HistogramOpts{
|
|
609
|
+
Name: "http_request_duration_seconds",
|
|
610
|
+
Buckets: prometheus.DefBuckets,
|
|
611
|
+
},
|
|
612
|
+
[]string{"method", "path", "status"},
|
|
613
|
+
)
|
|
614
|
+
|
|
615
|
+
func init() { prometheus.MustRegister(requestDuration) }
|
|
616
|
+
|
|
617
|
+
// Expose metrics endpoint
|
|
618
|
+
mux.Handle("GET /metrics", promhttp.Handler())
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
- Export RED metrics: Rate, Errors, Duration.
|
|
622
|
+
- Use OpenTelemetry SDK for traces + metrics combined.
|
|
623
|
+
- Use runtime metrics exporter for goroutine count, GC stats, memory usage.
|
|
624
|
+
|
|
625
|
+
---
|
|
626
|
+
|
|
627
|
+
## 8. Decision Trees
|
|
628
|
+
|
|
629
|
+
### Which HTTP Framework?
|
|
630
|
+
|
|
631
|
+
```
|
|
632
|
+
Need an HTTP server?
|
|
633
|
+
|
|
|
634
|
+
+-- How many endpoints?
|
|
635
|
+
|
|
|
636
|
+
+-- < 10 endpoints, simple routing
|
|
637
|
+
| --> stdlib net/http (Go 1.22+)
|
|
638
|
+
| Zero dependencies, method routing, path params built in.
|
|
639
|
+
|
|
|
640
|
+
+-- 10-50 endpoints, need middleware composition
|
|
641
|
+
| --> Chi
|
|
642
|
+
| net/http compatible, grouped routes, standard middleware works.
|
|
643
|
+
| Best for teams that value stdlib alignment.
|
|
644
|
+
|
|
|
645
|
+
+-- 50+ endpoints, large team, need ecosystem (swagger, validation)
|
|
646
|
+
|
|
|
647
|
+
+-- Performance-critical, willing to couple to framework?
|
|
648
|
+
| --> Gin
|
|
649
|
+
| Fastest benchmarks, large middleware ecosystem.
|
|
650
|
+
| Tradeoff: gin.Context is not stdlib-compatible.
|
|
651
|
+
|
|
|
652
|
+
+-- Prefer clean API, stdlib context, built-in features?
|
|
653
|
+
--> Echo
|
|
654
|
+
Returns errors from handlers, built-in file serving,
|
|
655
|
+
WebSocket, HTTP/2 support.
|
|
656
|
+
```
|
|
657
|
+
|
|
658
|
+
### Which Database Library?
|
|
659
|
+
|
|
660
|
+
```
|
|
661
|
+
Working with a database in Go?
|
|
662
|
+
|
|
|
663
|
+
+-- PostgreSQL only?
|
|
664
|
+
| |
|
|
665
|
+
| +-- Team is comfortable writing SQL?
|
|
666
|
+
| | |
|
|
667
|
+
| | +-- Yes --> sqlc (write SQL, generate type-safe Go code)
|
|
668
|
+
| | | Zero runtime overhead, compile-time safety.
|
|
669
|
+
| | |
|
|
670
|
+
| | +-- No, want ORM convenience --> GORM or ent
|
|
671
|
+
| |
|
|
672
|
+
| +-- Need maximum performance / Postgres-specific features?
|
|
673
|
+
| --> pgx v5 (direct driver, COPY, LISTEN/NOTIFY, batch)
|
|
674
|
+
| 30-50% faster than database/sql for Postgres.
|
|
675
|
+
|
|
|
676
|
+
+-- Multiple databases (MySQL, SQLite, Postgres)?
|
|
677
|
+
| --> GORM (broad driver support, auto-migration)
|
|
678
|
+
| or database/sql + sqlx (lightweight, multi-DB)
|
|
679
|
+
|
|
|
680
|
+
+-- Complex graph-like data model with relationships?
|
|
681
|
+
--> ent (code-first schema, graph traversal API)
|
|
682
|
+
Strong type safety, generated code, Meta-backed.
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
### When Channels vs. Mutexes?
|
|
686
|
+
|
|
687
|
+
```
|
|
688
|
+
Need to share state between goroutines?
|
|
689
|
+
|
|
|
690
|
+
+-- Is data flowing from producer to consumer?
|
|
691
|
+
| --> Channel
|
|
692
|
+
| Pipeline pattern, fan-out/fan-in, signaling completion.
|
|
693
|
+
|
|
|
694
|
+
+-- Are you protecting shared state (map, counter, cache)?
|
|
695
|
+
| |
|
|
696
|
+
| +-- Read-heavy workload?
|
|
697
|
+
| | --> sync.RWMutex (concurrent reads, exclusive writes)
|
|
698
|
+
| |
|
|
699
|
+
| +-- Simple counter?
|
|
700
|
+
| | --> sync/atomic (lock-free, lowest overhead)
|
|
701
|
+
| |
|
|
702
|
+
| +-- General case?
|
|
703
|
+
| --> sync.Mutex (simplest, lowest cognitive overhead)
|
|
704
|
+
|
|
|
705
|
+
+-- Need to coordinate N goroutines + collect first error?
|
|
706
|
+
| --> errgroup.Group (with context cancellation)
|
|
707
|
+
|
|
|
708
|
+
+-- Need one-time initialization?
|
|
709
|
+
--> sync.Once
|
|
710
|
+
```
|
|
711
|
+
|
|
712
|
+
---
|
|
713
|
+
|
|
714
|
+
## 9. Code Examples
|
|
715
|
+
|
|
716
|
+
### Graceful HTTP Server Shutdown
|
|
717
|
+
|
|
718
|
+
```go
|
|
719
|
+
func main() {
|
|
720
|
+
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
|
721
|
+
defer stop()
|
|
722
|
+
|
|
723
|
+
srv := &http.Server{
|
|
724
|
+
Addr: ":8080",
|
|
725
|
+
Handler: newRouter(),
|
|
726
|
+
ReadTimeout: 5 * time.Second,
|
|
727
|
+
WriteTimeout: 10 * time.Second,
|
|
728
|
+
IdleTimeout: 120 * time.Second,
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
go func() {
|
|
732
|
+
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
|
733
|
+
slog.Error("server failed", "error", err)
|
|
734
|
+
os.Exit(1)
|
|
735
|
+
}
|
|
736
|
+
}()
|
|
737
|
+
|
|
738
|
+
<-ctx.Done()
|
|
739
|
+
slog.Info("shutting down gracefully")
|
|
740
|
+
|
|
741
|
+
shutdownCtx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
|
742
|
+
defer cancel()
|
|
743
|
+
if err := srv.Shutdown(shutdownCtx); err != nil {
|
|
744
|
+
slog.Error("shutdown error", "error", err)
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
```
|
|
748
|
+
|
|
749
|
+
### Repository Pattern with Interface
|
|
750
|
+
|
|
751
|
+
```go
|
|
752
|
+
// internal/domain/user.go -- domain defines the interface
|
|
753
|
+
type UserRepository interface {
|
|
754
|
+
FindByID(ctx context.Context, id int64) (*User, error)
|
|
755
|
+
Save(ctx context.Context, user *User) error
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// internal/repository/postgres/user.go -- adapter implements it
|
|
759
|
+
type pgUserRepo struct {
|
|
760
|
+
pool *pgxpool.Pool
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
func NewUserRepo(pool *pgxpool.Pool) domain.UserRepository {
|
|
764
|
+
return &pgUserRepo{pool: pool}
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
func (r *pgUserRepo) FindByID(ctx context.Context, id int64) (*domain.User, error) {
|
|
768
|
+
var u domain.User
|
|
769
|
+
err := r.pool.QueryRow(ctx,
|
|
770
|
+
"SELECT id, name, email FROM users WHERE id = $1", id,
|
|
771
|
+
).Scan(&u.ID, &u.Name, &u.Email)
|
|
772
|
+
if errors.Is(err, pgx.ErrNoRows) {
|
|
773
|
+
return nil, domain.ErrNotFound
|
|
774
|
+
}
|
|
775
|
+
return &u, err
|
|
776
|
+
}
|
|
777
|
+
```
|
|
778
|
+
|
|
779
|
+
### Middleware Chain (stdlib-compatible)
|
|
780
|
+
|
|
781
|
+
```go
|
|
782
|
+
func loggingMiddleware(next http.Handler) http.Handler {
|
|
783
|
+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
784
|
+
start := time.Now()
|
|
785
|
+
sw := &statusWriter{ResponseWriter: w, status: 200}
|
|
786
|
+
next.ServeHTTP(sw, r)
|
|
787
|
+
slog.Info("request",
|
|
788
|
+
slog.String("method", r.Method),
|
|
789
|
+
slog.String("path", r.URL.Path),
|
|
790
|
+
slog.Int("status", sw.status),
|
|
791
|
+
slog.Duration("latency", time.Since(start)),
|
|
792
|
+
)
|
|
793
|
+
})
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
type statusWriter struct {
|
|
797
|
+
http.ResponseWriter
|
|
798
|
+
status int
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
func (w *statusWriter) WriteHeader(code int) {
|
|
802
|
+
w.status = code
|
|
803
|
+
w.ResponseWriter.WriteHeader(code)
|
|
804
|
+
}
|
|
805
|
+
```
|
|
806
|
+
|
|
807
|
+
### Worker Pool with Bounded Concurrency
|
|
808
|
+
|
|
809
|
+
```go
|
|
810
|
+
func processItems(ctx context.Context, items []Item, maxWorkers int) error {
|
|
811
|
+
g, ctx := errgroup.WithContext(ctx)
|
|
812
|
+
g.SetLimit(maxWorkers) // Go 1.20+: built-in concurrency limiter
|
|
813
|
+
|
|
814
|
+
for _, item := range items {
|
|
815
|
+
g.Go(func() error {
|
|
816
|
+
return process(ctx, item)
|
|
817
|
+
})
|
|
818
|
+
}
|
|
819
|
+
return g.Wait()
|
|
820
|
+
}
|
|
821
|
+
```
|
|
822
|
+
|
|
823
|
+
### Functional Options Pattern
|
|
824
|
+
|
|
825
|
+
```go
|
|
826
|
+
type Server struct {
|
|
827
|
+
addr string
|
|
828
|
+
timeout time.Duration
|
|
829
|
+
logger *slog.Logger
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
type Option func(*Server)
|
|
833
|
+
|
|
834
|
+
func WithAddr(addr string) Option { return func(s *Server) { s.addr = addr } }
|
|
835
|
+
func WithTimeout(d time.Duration) Option { return func(s *Server) { s.timeout = d } }
|
|
836
|
+
func WithLogger(l *slog.Logger) Option { return func(s *Server) { s.logger = l } }
|
|
837
|
+
|
|
838
|
+
func NewServer(opts ...Option) *Server {
|
|
839
|
+
s := &Server{
|
|
840
|
+
addr: ":8080",
|
|
841
|
+
timeout: 30 * time.Second,
|
|
842
|
+
logger: slog.Default(),
|
|
843
|
+
}
|
|
844
|
+
for _, opt := range opts {
|
|
845
|
+
opt(s)
|
|
846
|
+
}
|
|
847
|
+
return s
|
|
848
|
+
}
|
|
849
|
+
```
|
|
850
|
+
|
|
851
|
+
---
|
|
852
|
+
|
|
853
|
+
*Researched: 2026-03-07 | Sources: [Effective Go](https://go.dev/doc/effective_go), [Go Blog: Routing Enhancements](https://go.dev/blog/routing-enhancements), [Go 1.24 Release Notes](https://go.dev/doc/go1.24), [Go GC Guide](https://go.dev/doc/gc-guide), [Go SQL Injection Prevention](https://go.dev/doc/database/sql-injection), [100 Go Mistakes](https://100go.co/), [Go Blog: Working with Errors](https://go.dev/blog/go1.13-errors), [Go Fuzzing Docs](https://go.dev/doc/security/fuzz/), [Eli Bendersky: HTTP Routing in Go 1.22](https://eli.thegreenplace.net/2023/better-http-server-routing-in-go-122/), [JetBrains: Comparing DB Packages](https://blog.jetbrains.com/go/2023/04/27/comparing-db-packages/), [Encore: Best Go Frameworks 2026](https://encore.dev/articles/best-go-backend-frameworks), [Encore: Advanced Concurrency](https://encore.dev/blog/advanced-go-concurrency), [Alex Edwards: Structuring Go Projects](https://www.alexedwards.net/blog/11-tips-for-structuring-your-go-projects), [Dash0: slog Guide](https://www.dash0.com/guides/logging-in-go-with-slog), [Calhoun.io: ServeMux vs Chi](https://www.calhoun.io/go-servemux-vs-chi/)*
|