@stackonward/cli 0.0.1 → 1.0.1
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/dist/index.js +4588 -205
- package/dist/index.js.map +1 -1
- package/dist/resources/apple/.claude/docs/architecture-template.md +54 -0
- package/dist/resources/apple/.claude/docs/architecture.md +52 -0
- package/dist/resources/apple/.claude/docs/index.md +13 -0
- package/dist/resources/apple/.claude/docs/security-lifecycle.md +57 -0
- package/dist/resources/apple/.claude/docs/stack.md +93 -0
- package/dist/resources/apple/.claude/docs/verification.md +63 -0
- package/dist/resources/apple/AGENTS.md +397 -0
- package/dist/resources/apple/CLAUDE.md +397 -0
- package/dist/resources/apple/Gemfile +2 -0
- package/dist/resources/apple/Gemfile.lock +365 -0
- package/dist/resources/apple/_gitignore +14 -0
- package/dist/resources/apple/fastlane/Fastfile +123 -0
- package/dist/resources/components/nuxt/site-source/app/app.vue +42 -0
- package/dist/resources/components/nuxt/site-source/app/assets/css/site-shell.css +1035 -0
- package/dist/resources/components/nuxt/site-source/app/assets/icons/brand/.gitkeep +0 -0
- package/dist/resources/components/nuxt/site-source/app/assets/icons/common/.gitkeep +0 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ApplicationHeader.vue +35 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ApplicationShell.vue +56 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ApplicationSidebar.vue +40 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/BackToTop.vue +42 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ContentArticlePage.vue +40 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ContentListPage.vue +30 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/CookieConsent.vue +18 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/MarketingFooter.vue +52 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/MarketingHeader.vue +106 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/MarketingShell.vue +35 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/SiteBrand.vue +10 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/StaticPage.vue +21 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ToastViewport.vue +25 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BaseButton.vue +86 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BaseGradientBorder.vue +59 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BaseModal.vue +131 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BasePopover.vue +150 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BaseText.vue +138 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/CheckoutStatus.vue +112 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/CheckoutSummary.vue +172 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/GoogleSignInButton.vue +113 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/InfiniteScroll.vue +123 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/YoutubeEmbed.vue +126 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useAnalytics.ts +24 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useCheckout.ts +121 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useConsent.ts +31 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useGoogleIdentity.ts +163 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useNavigation.ts +11 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useSeo.ts +33 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useSiteShell.ts +58 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useToasts.ts +48 -0
- package/dist/resources/components/nuxt/site-source/app/layouts/app.vue +5 -0
- package/dist/resources/components/nuxt/site-source/app/layouts/default.vue +5 -0
- package/dist/resources/components/nuxt/site-source/app/plugins/analytics.client.ts +121 -0
- package/dist/resources/components/nuxt/site-source/app/plugins/google-identity.client.ts +24 -0
- package/dist/resources/components/nuxt/site-source/app/theme/accordion.ts +9 -0
- package/dist/resources/components/nuxt/site-source/app/theme/breadcrumb.ts +8 -0
- package/dist/resources/components/nuxt/site-source/app/theme/button.ts +92 -0
- package/dist/resources/components/nuxt/site-source/app/theme/carousel.ts +11 -0
- package/dist/resources/components/nuxt/site-source/app/theme/checkbox.ts +12 -0
- package/dist/resources/components/nuxt/site-source/app/theme/index.ts +30 -0
- package/dist/resources/components/nuxt/site-source/app/theme/input.ts +47 -0
- package/dist/resources/components/nuxt/site-source/app/theme/modal.ts +9 -0
- package/dist/resources/components/nuxt/site-source/app/theme/pagination.ts +6 -0
- package/dist/resources/components/nuxt/site-source/app/theme/select.ts +23 -0
- package/dist/resources/components/nuxt/site-source/app/theme/stepper.ts +10 -0
- package/dist/resources/components/nuxt/site-source/app/theme/toast.ts +8 -0
- package/dist/resources/components/nuxt/site-source/app/theme/tooltip.ts +6 -0
- package/dist/resources/components/nuxt/site-source/app/types/site-shell.ts +85 -0
- package/dist/resources/components/react/ui/Button.tsx +73 -0
- package/dist/resources/components/react/ui/Input.tsx +44 -0
- package/dist/resources/components/registry.json +355 -0
- package/dist/resources/components/vue/feedback/Toast.vue +120 -0
- package/dist/resources/components/vue/feedback/useToast.ts +70 -0
- package/dist/resources/components/vue/media/FileUpload.vue +229 -0
- package/dist/resources/components/vue/media/VideoPlayer.vue +157 -0
- package/dist/resources/components/vue/ui/AppImage.vue +147 -0
- package/dist/resources/components/vue/ui/BottomSheet.vue +217 -0
- package/dist/resources/components/vue/ui/Button.vue +154 -0
- package/dist/resources/components/vue/ui/Card.vue +111 -0
- package/dist/resources/components/vue/ui/Input.vue +113 -0
- package/dist/resources/components/vue/ui/Modal.vue +193 -0
- package/dist/resources/components/vue/ui/ScrollArea.vue +163 -0
- package/dist/resources/components/vue/ui/Tooltip.vue +115 -0
- package/dist/resources/registry.json +158 -0
- package/dist/resources/snippets/node/cache.ts +116 -0
- package/dist/resources/snippets/node/date.ts +126 -0
- package/dist/resources/snippets/node/logger.ts +104 -0
- package/dist/resources/snippets/node/validation.ts +132 -0
- package/dist/resources/snippets/react/useDebounce.ts +90 -0
- package/dist/resources/snippets/registry.json +65 -0
- package/dist/resources/snippets/vue/useAsync.ts +96 -0
- package/dist/resources/snippets/vue/usePagination.ts +102 -0
- package/dist/resources/templates/base/.claude/docs/architecture-template.md +459 -0
- package/dist/resources/templates/base/.claude/docs/architecture.md +137 -0
- package/dist/resources/templates/base/.claude/docs/index.md +42 -0
- package/dist/resources/templates/base/.claude/docs/security-lifecycle.md +129 -0
- package/dist/resources/templates/base/.claude/docs/verification.md +121 -0
- package/dist/resources/templates/base/AGENTS.md +415 -0
- package/dist/resources/templates/base/CLAUDE.md +415 -0
- package/dist/resources/templates/go-backend/.claude/docs/api-design.md +486 -0
- package/dist/resources/templates/go-backend/.claude/docs/architecture-template.md +449 -0
- package/dist/resources/templates/go-backend/.claude/docs/check-list.md +155 -0
- package/dist/resources/templates/go-backend/.claude/docs/database.md +369 -0
- package/dist/resources/templates/go-backend/.claude/docs/e2e-standards.md +161 -0
- package/dist/resources/templates/go-backend/.claude/docs/error-handling.md +558 -0
- package/dist/resources/templates/go-backend/.claude/docs/event-runtime-boundary.md +124 -0
- package/dist/resources/templates/go-backend/.claude/docs/identifier-contract.md +195 -0
- package/dist/resources/templates/go-backend/.claude/docs/index.md +22 -0
- package/dist/resources/templates/go-backend/.claude/docs/logging.md +314 -0
- package/dist/resources/templates/go-backend/.claude/docs/mediagen-provider-onboarding-sop.md +917 -0
- package/dist/resources/templates/go-backend/.claude/docs/mediagen-provider-quick-reference.md +195 -0
- package/dist/resources/templates/go-backend/.claude/docs/module-standards.md +309 -0
- package/dist/resources/templates/go-backend/.claude/docs/openapi-contract.md +141 -0
- package/dist/resources/templates/go-backend/.claude/docs/payment-gateway-onboarding.md +283 -0
- package/dist/resources/templates/go-backend/.claude/docs/platform-boundary.md +191 -0
- package/dist/resources/templates/go-backend/.claude/docs/quality-gates.md +112 -0
- package/dist/resources/templates/go-backend/.dockerignore +6 -0
- package/dist/resources/templates/go-backend/.env.example +13 -0
- package/dist/resources/templates/go-backend/.gitattributes +2 -0
- package/dist/resources/templates/go-backend/AGENTS.md +1139 -0
- package/dist/resources/templates/go-backend/CLAUDE.md +1139 -0
- package/dist/resources/templates/go-backend/Dockerfile +14 -0
- package/dist/resources/templates/go-backend/Makefile +71 -0
- package/dist/resources/templates/go-backend/README.md +66 -0
- package/dist/resources/templates/go-backend/_gitignore +10 -0
- package/dist/resources/templates/go-backend/api/openapi/README.md +29 -0
- package/dist/resources/templates/go-backend/api/openapi/dist/artifact-manifest.json +19 -0
- package/dist/resources/templates/go-backend/api/openapi/dist/conformance-matrix.json +276 -0
- package/dist/resources/templates/go-backend/api/openapi/document.go +30 -0
- package/dist/resources/templates/go-backend/api/openapi/package.json +28 -0
- package/dist/resources/templates/go-backend/api/openapi/pnpm-lock.yaml +3052 -0
- package/dist/resources/templates/go-backend/api/openapi/redocly-source.yaml +18 -0
- package/dist/resources/templates/go-backend/api/openapi/redocly.yaml +8 -0
- package/dist/resources/templates/go-backend/api/openapi/sdk-generators.json +16 -0
- package/dist/resources/templates/go-backend/api/openapi/service-registry.json +39 -0
- package/dist/resources/templates/go-backend/api/openapi/services/product-api/conformance/runtime.arazzo.yaml +65 -0
- package/dist/resources/templates/go-backend/api/openapi/services/product-api/dist/internal.openapi.json +327 -0
- package/dist/resources/templates/go-backend/api/openapi/services/product-api/dist/runtime-contract.json +56 -0
- package/dist/resources/templates/go-backend/api/openapi/services/product-api/openapi.yaml +222 -0
- package/dist/resources/templates/go-backend/api/openapi/services/worker/conformance/runtime.arazzo.yaml +65 -0
- package/dist/resources/templates/go-backend/api/openapi/services/worker/dist/internal.openapi.json +327 -0
- package/dist/resources/templates/go-backend/api/openapi/services/worker/dist/runtime-contract.json +56 -0
- package/dist/resources/templates/go-backend/api/openapi/services/worker/openapi.yaml +222 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/breaking.mjs +416 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/build.mjs +103 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/conformance_coverage.mjs +111 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/contract_compiler.mjs +62 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/contract_policy.mjs +208 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/delegated_contract.mjs +302 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/deterministic_archive.mjs +69 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/documentation_example_privacy.mjs +93 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/documentation_projection.mjs +498 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/documentation_quality.mjs +346 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/git_artifact_history.mjs +188 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/manifest.mjs +170 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/overlay.mjs +98 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/project.mjs +549 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/route_contract.mjs +156 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/runtime_conformance.mjs +193 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/scalar_asset_localization.mjs +164 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/sdk_generator.mjs +229 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/semantic_version.mjs +64 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/service_contract_inputs.mjs +16 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/breaking.test.mjs +365 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/build.test.mjs +42 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/conformance_coverage.test.mjs +88 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/contract_policy.test.mjs +257 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/delegated_contract.test.mjs +205 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/documentation_example_privacy.test.mjs +51 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/documentation_projection.test.mjs +368 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/documentation_quality.test.mjs +151 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/git_artifact_history.test.mjs +60 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/head_policy.test.mjs +8 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/overlay.test.mjs +44 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/projection.test.mjs +270 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/redocly_documentation_rules.test.mjs +146 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/release_manifest.test.mjs +76 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/route_contract.test.mjs +119 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/runtime_conformance.test.mjs +75 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/scalar_asset_localization.test.mjs +50 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/sdk_generator.test.mjs +31 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/semantic_version.test.mjs +60 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/service_contract_inputs.test.mjs +27 -0
- package/dist/resources/templates/go-backend/cmd/internal/runtime/resources.go +125 -0
- package/dist/resources/templates/go-backend/cmd/internal/runtime/runtime.go +102 -0
- package/dist/resources/templates/go-backend/cmd/internal/runtime/runtime_test.go +70 -0
- package/dist/resources/templates/go-backend/cmd/product-api/lifecycle_test.go +58 -0
- package/dist/resources/templates/go-backend/cmd/product-api/main.go +32 -0
- package/dist/resources/templates/go-backend/cmd/product-api/wire.go +13 -0
- package/dist/resources/templates/go-backend/cmd/product-api/wire_gen.go +94 -0
- package/dist/resources/templates/go-backend/cmd/worker/main.go +47 -0
- package/dist/resources/templates/go-backend/cmd/worker/wire.go +14 -0
- package/dist/resources/templates/go-backend/cmd/worker/wire_gen.go +111 -0
- package/dist/resources/templates/go-backend/configs/config.yaml +37 -0
- package/dist/resources/templates/go-backend/deployments/compose.yaml +71 -0
- package/dist/resources/templates/go-backend/docs/openapi-provenance.json +489 -0
- package/dist/resources/templates/go-backend/docs/runtime-provenance.json +175 -0
- package/dist/resources/templates/go-backend/docs/source-provenance.json +3568 -0
- package/dist/resources/templates/go-backend/docs/standards-provenance.json +1624 -0
- package/dist/resources/templates/go-backend/go.mod +256 -0
- package/dist/resources/templates/go-backend/go.sum +805 -0
- package/dist/resources/templates/go-backend/internal/common/canonicaljson/canonical.go +370 -0
- package/dist/resources/templates/go-backend/internal/common/canonicaljson/canonical_test.go +223 -0
- package/dist/resources/templates/go-backend/internal/common/checkoutbff/contracts.go +125 -0
- package/dist/resources/templates/go-backend/internal/common/checkoutbff/platform_client.go +212 -0
- package/dist/resources/templates/go-backend/internal/common/checkoutbff/platform_client_test.go +319 -0
- package/dist/resources/templates/go-backend/internal/common/contentaccess/contentaccess.go +50 -0
- package/dist/resources/templates/go-backend/internal/common/contracts/contact.go +85 -0
- package/dist/resources/templates/go-backend/internal/common/ctxutil/identity.go +20 -0
- package/dist/resources/templates/go-backend/internal/common/ctxutil/product.go +53 -0
- package/dist/resources/templates/go-backend/internal/common/enumdomain/payment.go +12 -0
- package/dist/resources/templates/go-backend/internal/common/enums/dto_admin.go +9 -0
- package/dist/resources/templates/go-backend/internal/common/enums/enum.go +1247 -0
- package/dist/resources/templates/go-backend/internal/common/enums/handler_admin.go +66 -0
- package/dist/resources/templates/go-backend/internal/common/enums/module.go +46 -0
- package/dist/resources/templates/go-backend/internal/common/enums/provider.go +10 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register.go +11 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_audit.go +274 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_command_replay.go +12 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_config.go +27 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_locale.go +37 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_ops.go +14 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_outbox.go +15 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_rule_expression.go +63 -0
- package/dist/resources/templates/go-backend/internal/common/enums/registry.go +77 -0
- package/dist/resources/templates/go-backend/internal/common/httporigin/origin.go +62 -0
- package/dist/resources/templates/go-backend/internal/common/httporigin/origin_test.go +38 -0
- package/dist/resources/templates/go-backend/internal/common/iamcredential/plaintext.go +35 -0
- package/dist/resources/templates/go-backend/internal/common/iamcredential/plaintext_test.go +29 -0
- package/dist/resources/templates/go-backend/internal/common/iamscope/scope.go +212 -0
- package/dist/resources/templates/go-backend/internal/common/iamscope/scope_binding.go +26 -0
- package/dist/resources/templates/go-backend/internal/common/iamscope/scope_filter.go +173 -0
- package/dist/resources/templates/go-backend/internal/common/iamscope/scope_filter_test.go +279 -0
- package/dist/resources/templates/go-backend/internal/common/internalapi/authorization_details.go +10 -0
- package/dist/resources/templates/go-backend/internal/common/internalapi/route_permission_policies.go +660 -0
- package/dist/resources/templates/go-backend/internal/common/internalapi/route_permission_policies_test.go +331 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/audience_token_source.go +166 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/bootstrap_token_exchanger.go +183 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/bound_service_token_signer.go +52 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/delegated_access_token_exchanger.go +189 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/delegated_access_token_exchanger_test.go +159 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/product_scoped_service_token_signer.go +92 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/provider.go +25 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/request_signer.go +86 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/resolver.go +69 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/resolver_test.go +42 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/route_scope.go +95 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/route_scope_test.go +78 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/service_identity_test.go +387 -0
- package/dist/resources/templates/go-backend/internal/common/jsonschema/compiler.go +100 -0
- package/dist/resources/templates/go-backend/internal/common/jsonschema/compiler_test.go +41 -0
- package/dist/resources/templates/go-backend/internal/common/jwksapi/handler.go +83 -0
- package/dist/resources/templates/go-backend/internal/common/jwksapi/handler_test.go +104 -0
- package/dist/resources/templates/go-backend/internal/common/locale/locale.go +145 -0
- package/dist/resources/templates/go-backend/internal/common/locale/locale_test.go +75 -0
- package/dist/resources/templates/go-backend/internal/common/mediaref/mediaref.go +54 -0
- package/dist/resources/templates/go-backend/internal/common/mediaref/mediaref_test.go +77 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/apikey_auth.go +320 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/apikey_throttle.go +158 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/auth.go +40 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/auth_test.go +50 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/client_context.go +86 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/cors.go +68 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/event_context.go +18 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/gateway_identity.go +279 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/helpers.go +159 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_delegated_route_permission.go +171 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_delegated_token_auth.go +151 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_delegated_token_auth_test.go +99 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_service_identity.go +138 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_service_token_auth.go +74 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/idempotent.go +273 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/idempotent_test.go +83 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/internal_route_permission.go +45 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/internal_route_permission_test.go +186 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/logging.go +191 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/metrics.go +45 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/middleware_test.go +1516 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/principal_context.go +160 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/principal_context_test.go +355 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/product_context.go +100 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/recovery.go +40 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/referral_attribution.go +178 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/requestid.go +48 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/resource_permission.go +790 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/resource_permission_test.go +440 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/service_credential_auth.go +67 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/tenant.go +148 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/throttle.go +310 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/trusted_client_ip.go +23 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/trusted_client_ip_test.go +60 -0
- package/dist/resources/templates/go-backend/internal/common/money/currency.go +25 -0
- package/dist/resources/templates/go-backend/internal/common/money/errors.go +23 -0
- package/dist/resources/templates/go-backend/internal/common/money/format.go +123 -0
- package/dist/resources/templates/go-backend/internal/common/money/format_test.go +204 -0
- package/dist/resources/templates/go-backend/internal/common/money/gateway.go +144 -0
- package/dist/resources/templates/go-backend/internal/common/money/gateway_test.go +165 -0
- package/dist/resources/templates/go-backend/internal/common/money/rounding.go +56 -0
- package/dist/resources/templates/go-backend/internal/common/money/rounding_test.go +51 -0
- package/dist/resources/templates/go-backend/internal/common/principal/context.go +56 -0
- package/dist/resources/templates/go-backend/internal/common/principal/principal.go +49 -0
- package/dist/resources/templates/go-backend/internal/common/productcode/code.go +24 -0
- package/dist/resources/templates/go-backend/internal/common/productcode/code_test.go +35 -0
- package/dist/resources/templates/go-backend/internal/common/providerconfig/schema.go +577 -0
- package/dist/resources/templates/go-backend/internal/common/providerconfig/schema_test.go +47 -0
- package/dist/resources/templates/go-backend/internal/common/requestprivacy/request.go +246 -0
- package/dist/resources/templates/go-backend/internal/common/requestprivacy/request_test.go +170 -0
- package/dist/resources/templates/go-backend/internal/common/response/pagination.go +60 -0
- package/dist/resources/templates/go-backend/internal/common/response/response.go +110 -0
- package/dist/resources/templates/go-backend/internal/common/response/response_test.go +463 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/ast.go +141 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/ast_test.go +81 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/canonical.go +184 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/canonical_test.go +319 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/decoder.go +555 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/decoder_test.go +260 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/errors.go +55 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/evaluator.go +96 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/evaluator_test.go +220 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/fuzz_test.go +116 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/limits.go +331 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/schema.go +412 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/schema_test.go +164 -0
- package/dist/resources/templates/go-backend/internal/common/runtimeinput/runtime_input.go +627 -0
- package/dist/resources/templates/go-backend/internal/common/runtimeinput/runtime_input_test.go +245 -0
- package/dist/resources/templates/go-backend/internal/common/semver/errors.go +6 -0
- package/dist/resources/templates/go-backend/internal/common/semver/semver.go +125 -0
- package/dist/resources/templates/go-backend/internal/common/semver/semver_test.go +205 -0
- package/dist/resources/templates/go-backend/internal/common/serviceidentity/audience.go +48 -0
- package/dist/resources/templates/go-backend/internal/common/serviceidentity/audience_test.go +35 -0
- package/dist/resources/templates/go-backend/internal/common/serviceidentity/resource_identifier.go +33 -0
- package/dist/resources/templates/go-backend/internal/common/serviceidentity/resource_identifier_test.go +32 -0
- package/dist/resources/templates/go-backend/internal/common/tradeno/generator.go +99 -0
- package/dist/resources/templates/go-backend/internal/common/tradeno/generator_test.go +396 -0
- package/dist/resources/templates/go-backend/internal/common/tradeno/prefix.go +247 -0
- package/dist/resources/templates/go-backend/internal/common/types/asset_url.go +11 -0
- package/dist/resources/templates/go-backend/internal/common/types/billing.go +89 -0
- package/dist/resources/templates/go-backend/internal/common/types/billing_test.go +77 -0
- package/dist/resources/templates/go-backend/internal/common/types/country.go +74 -0
- package/dist/resources/templates/go-backend/internal/common/types/country_test.go +28 -0
- package/dist/resources/templates/go-backend/internal/common/types/currency.go +60 -0
- package/dist/resources/templates/go-backend/internal/common/types/identifiers.go +41 -0
- package/dist/resources/templates/go-backend/internal/common/types/operator.go +28 -0
- package/dist/resources/templates/go-backend/internal/common/types/subscription_entitlement.go +24 -0
- package/dist/resources/templates/go-backend/internal/common/types/subscription_entitlement_test.go +35 -0
- package/dist/resources/templates/go-backend/internal/common/types/tier.go +72 -0
- package/dist/resources/templates/go-backend/internal/common/types/types.go +411 -0
- package/dist/resources/templates/go-backend/internal/common/types/types_test.go +295 -0
- package/dist/resources/templates/go-backend/internal/common/utils/constants.go +100 -0
- package/dist/resources/templates/go-backend/internal/common/utils/crypto.go +158 -0
- package/dist/resources/templates/go-backend/internal/common/utils/crypto_test.go +345 -0
- package/dist/resources/templates/go-backend/internal/common/utils/duration.go +25 -0
- package/dist/resources/templates/go-backend/internal/common/utils/helpers.go +18 -0
- package/dist/resources/templates/go-backend/internal/common/utils/json.go +62 -0
- package/dist/resources/templates/go-backend/internal/common/utils/json_test.go +76 -0
- package/dist/resources/templates/go-backend/internal/common/utils/pagination.go +51 -0
- package/dist/resources/templates/go-backend/internal/common/utils/pagination_test.go +45 -0
- package/dist/resources/templates/go-backend/internal/common/utils/pointer.go +107 -0
- package/dist/resources/templates/go-backend/internal/common/utils/pointer_test.go +15 -0
- package/dist/resources/templates/go-backend/internal/common/utils/slice.go +24 -0
- package/dist/resources/templates/go-backend/internal/common/utils/snowflake.go +110 -0
- package/dist/resources/templates/go-backend/internal/common/utils/snowflake_test.go +316 -0
- package/dist/resources/templates/go-backend/internal/common/utils/string.go +16 -0
- package/dist/resources/templates/go-backend/internal/common/utils/timefmt.go +42 -0
- package/dist/resources/templates/go-backend/internal/common/validator/validator.go +136 -0
- package/dist/resources/templates/go-backend/internal/common/validator/validator_test.go +240 -0
- package/dist/resources/templates/go-backend/internal/common/youtubeapi/client.go +224 -0
- package/dist/resources/templates/go-backend/internal/core/apicontract/document.go +269 -0
- package/dist/resources/templates/go-backend/internal/core/apicontract/document_test.go +104 -0
- package/dist/resources/templates/go-backend/internal/core/apicontract/route_validator.go +78 -0
- package/dist/resources/templates/go-backend/internal/core/apicontract/route_validator_test.go +108 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/assets/scalar-api-reference.js +2385 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/assets/scalar-api-reference.metadata.json +10 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/route.go +107 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/route_test.go +200 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/scalar.go +117 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/scalar_test.go +99 -0
- package/dist/resources/templates/go-backend/internal/core/audit/access_log_policy.go +91 -0
- package/dist/resources/templates/go-backend/internal/core/audit/access_log_policy_test.go +51 -0
- package/dist/resources/templates/go-backend/internal/core/audit/actor_resolver.go +36 -0
- package/dist/resources/templates/go-backend/internal/core/audit/constants.go +30 -0
- package/dist/resources/templates/go-backend/internal/core/audit/context.go +119 -0
- package/dist/resources/templates/go-backend/internal/core/audit/context_test.go +310 -0
- package/dist/resources/templates/go-backend/internal/core/audit/dto.go +468 -0
- package/dist/resources/templates/go-backend/internal/core/audit/dto_admin.go +172 -0
- package/dist/resources/templates/go-backend/internal/core/audit/enum.go +460 -0
- package/dist/resources/templates/go-backend/internal/core/audit/enum_test.go +314 -0
- package/dist/resources/templates/go-backend/internal/core/audit/errors.go +9 -0
- package/dist/resources/templates/go-backend/internal/core/audit/handler.go +568 -0
- package/dist/resources/templates/go-backend/internal/core/audit/listener.go +319 -0
- package/dist/resources/templates/go-backend/internal/core/audit/listener_test.go +98 -0
- package/dist/resources/templates/go-backend/internal/core/audit/middleware.go +669 -0
- package/dist/resources/templates/go-backend/internal/core/audit/middleware_test.go +268 -0
- package/dist/resources/templates/go-backend/internal/core/audit/model.go +306 -0
- package/dist/resources/templates/go-backend/internal/core/audit/partition_job.go +316 -0
- package/dist/resources/templates/go-backend/internal/core/audit/ports.go +9 -0
- package/dist/resources/templates/go-backend/internal/core/audit/provider.go +30 -0
- package/dist/resources/templates/go-backend/internal/core/audit/repository.go +1007 -0
- package/dist/resources/templates/go-backend/internal/core/audit/repository_test.go +934 -0
- package/dist/resources/templates/go-backend/internal/core/audit/router.go +85 -0
- package/dist/resources/templates/go-backend/internal/core/audit/service.go +770 -0
- package/dist/resources/templates/go-backend/internal/core/audit/service_test.go +331 -0
- package/dist/resources/templates/go-backend/internal/core/audit/vo_admin.go +475 -0
- package/dist/resources/templates/go-backend/internal/core/cache/config.go +30 -0
- package/dist/resources/templates/go-backend/internal/core/cache/key.go +41 -0
- package/dist/resources/templates/go-backend/internal/core/cache/key_test.go +62 -0
- package/dist/resources/templates/go-backend/internal/core/cache/l1.go +153 -0
- package/dist/resources/templates/go-backend/internal/core/cache/l1_test.go +212 -0
- package/dist/resources/templates/go-backend/internal/core/cache/manager.go +278 -0
- package/dist/resources/templates/go-backend/internal/core/cache/manager_provider.go +24 -0
- package/dist/resources/templates/go-backend/internal/core/cache/metrics.go +126 -0
- package/dist/resources/templates/go-backend/internal/core/cache/namespace.go +46 -0
- package/dist/resources/templates/go-backend/internal/core/cache/namespace_test.go +90 -0
- package/dist/resources/templates/go-backend/internal/core/cache/options.go +39 -0
- package/dist/resources/templates/go-backend/internal/core/cache/options_test.go +96 -0
- package/dist/resources/templates/go-backend/internal/core/cache/redis.go +311 -0
- package/dist/resources/templates/go-backend/internal/core/cache/redis_test.go +51 -0
- package/dist/resources/templates/go-backend/internal/core/cache/serializer.go +31 -0
- package/dist/resources/templates/go-backend/internal/core/cache/serializer_test.go +139 -0
- package/dist/resources/templates/go-backend/internal/core/cache/singleflight.go +53 -0
- package/dist/resources/templates/go-backend/internal/core/cache/singleflight_test.go +211 -0
- package/dist/resources/templates/go-backend/internal/core/cache/warming.go +86 -0
- package/dist/resources/templates/go-backend/internal/core/clock/clock.go +66 -0
- package/dist/resources/templates/go-backend/internal/core/clock/clock_test.go +26 -0
- package/dist/resources/templates/go-backend/internal/core/clock/runtime_clock.go +283 -0
- package/dist/resources/templates/go-backend/internal/core/clock/runtime_clock_test.go +98 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/errors.go +6 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/model.go +90 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/model_test.go +79 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/namespace.go +7 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/persistence.go +269 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/persistence_test.go +185 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/provider.go +9 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/repository.go +22 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/service.go +853 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/service_persistence_test.go +432 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/service_test.go +891 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/types.go +121 -0
- package/dist/resources/templates/go-backend/internal/core/config/config.go +2069 -0
- package/dist/resources/templates/go-backend/internal/core/config/config_test.go +1122 -0
- package/dist/resources/templates/go-backend/internal/core/config/contract/contract_test.go +388 -0
- package/dist/resources/templates/go-backend/internal/core/config/contract/docs.go +198 -0
- package/dist/resources/templates/go-backend/internal/core/config/contract/verify.go +424 -0
- package/dist/resources/templates/go-backend/internal/core/config/enum.go +46 -0
- package/dist/resources/templates/go-backend/internal/core/config/metadata.go +717 -0
- package/dist/resources/templates/go-backend/internal/core/config/metadata_test.go +228 -0
- package/dist/resources/templates/go-backend/internal/core/config/product_admin_config_test.go +210 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/aes_gcm.go +111 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/aes_gcm_test.go +364 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/encryptor.go +12 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/envelope_encryptor.go +134 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/envelope_encryptor_test.go +118 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/pem.go +112 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/pem_test.go +44 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/provider.go +130 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/provider_test.go +92 -0
- package/dist/resources/templates/go-backend/internal/core/database/base_model.go +24 -0
- package/dist/resources/templates/go-backend/internal/core/database/clickhouse.go +121 -0
- package/dist/resources/templates/go-backend/internal/core/database/database.go +112 -0
- package/dist/resources/templates/go-backend/internal/core/database/database_logger_test.go +95 -0
- package/dist/resources/templates/go-backend/internal/core/database/errors.go +25 -0
- package/dist/resources/templates/go-backend/internal/core/database/metrics_plugin.go +105 -0
- package/dist/resources/templates/go-backend/internal/core/database/pool_collector.go +71 -0
- package/dist/resources/templates/go-backend/internal/core/database/read_replica.go +520 -0
- package/dist/resources/templates/go-backend/internal/core/database/transaction.go +170 -0
- package/dist/resources/templates/go-backend/internal/core/database/transaction_test.go +282 -0
- package/dist/resources/templates/go-backend/internal/core/distlock/lock.go +353 -0
- package/dist/resources/templates/go-backend/internal/core/distlock/lock_test.go +106 -0
- package/dist/resources/templates/go-backend/internal/core/errors/handler.go +189 -0
- package/dist/resources/templates/go-backend/internal/core/errors/handler_test.go +515 -0
- package/dist/resources/templates/go-backend/internal/core/eventbus/eventbus.go +667 -0
- package/dist/resources/templates/go-backend/internal/core/eventbus/eventbus_test.go +792 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/noop.go +22 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/provider.go +20 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/publisher.go +38 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/redis.go +109 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/routing.go +104 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/routing_test.go +71 -0
- package/dist/resources/templates/go-backend/internal/core/geoip/model.go +19 -0
- package/dist/resources/templates/go-backend/internal/core/geoip/service.go +88 -0
- package/dist/resources/templates/go-backend/internal/core/health/health.go +333 -0
- package/dist/resources/templates/go-backend/internal/core/health/health_test.go +27 -0
- package/dist/resources/templates/go-backend/internal/core/httpclient/client.go +772 -0
- package/dist/resources/templates/go-backend/internal/core/httpclient/client_test.go +287 -0
- package/dist/resources/templates/go-backend/internal/core/httpclient/download.go +578 -0
- package/dist/resources/templates/go-backend/internal/core/httpclient/download_test.go +374 -0
- package/dist/resources/templates/go-backend/internal/core/jwtkeyring/jwk.go +38 -0
- package/dist/resources/templates/go-backend/internal/core/jwtkeyring/keyring.go +144 -0
- package/dist/resources/templates/go-backend/internal/core/jwtkeyring/keyring_test.go +128 -0
- package/dist/resources/templates/go-backend/internal/core/jwtkeyring/registry.go +60 -0
- package/dist/resources/templates/go-backend/internal/core/logger/logger.go +53 -0
- package/dist/resources/templates/go-backend/internal/core/logger/logger_test.go +194 -0
- package/dist/resources/templates/go-backend/internal/core/observability/metrics.go +358 -0
- package/dist/resources/templates/go-backend/internal/core/observability/sentry.go +445 -0
- package/dist/resources/templates/go-backend/internal/core/observability/sentry_privacy_test.go +175 -0
- package/dist/resources/templates/go-backend/internal/core/observability/tracing.go +187 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/model.go +314 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/model_test.go +77 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/persistence.go +51 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/provider.go +23 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/relay.go +1138 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/relay_postgres_test.go +257 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/relay_test.go +690 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/rescheduler.go +164 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/rescheduler_test.go +209 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/writer.go +249 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/writer_postgres_test.go +170 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/writer_test.go +123 -0
- package/dist/resources/templates/go-backend/internal/core/provider.go +198 -0
- package/dist/resources/templates/go-backend/internal/core/queue/metrics_middleware.go +38 -0
- package/dist/resources/templates/go-backend/internal/core/queue/metrics_middleware_test.go +12 -0
- package/dist/resources/templates/go-backend/internal/core/queue/queue.go +288 -0
- package/dist/resources/templates/go-backend/internal/core/queue/queue_test.go +159 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/bulkhead.go +514 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/bulkhead_test.go +984 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/circuitbreaker.go +358 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/circuitbreaker_test.go +788 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/retry.go +318 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/retry_test.go +735 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/recorder.go +305 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/run_context.go +124 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/run_context_test.go +85 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/scheduler.go +1589 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/scheduler_control_test.go +808 -0
- package/dist/resources/templates/go-backend/internal/core/storage/oss_provider.go +398 -0
- package/dist/resources/templates/go-backend/internal/core/storage/oss_provider_test.go +89 -0
- package/dist/resources/templates/go-backend/internal/core/storage/path.go +110 -0
- package/dist/resources/templates/go-backend/internal/core/storage/path_test.go +301 -0
- package/dist/resources/templates/go-backend/internal/core/storage/s3_provider.go +489 -0
- package/dist/resources/templates/go-backend/internal/core/storage/s3_provider_test.go +60 -0
- package/dist/resources/templates/go-backend/internal/core/storage/storage.go +268 -0
- package/dist/resources/templates/go-backend/internal/core/storage/validation.go +225 -0
- package/dist/resources/templates/go-backend/internal/core/storage/validation_test.go +495 -0
- package/dist/resources/templates/go-backend/internal/core/temporal/logger.go +38 -0
- package/dist/resources/templates/go-backend/internal/core/temporal/provider.go +126 -0
- package/dist/resources/templates/go-backend/internal/core/temporal/provider_test.go +67 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/client.go +282 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/client_test.go +81 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/config.go +58 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/handler.go +53 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/hub.go +269 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/message.go +273 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/notifier.go +92 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/provider.go +33 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/action.go +77 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/action_test.go +238 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/condition.go +107 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/decision.go +256 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/enum.go +643 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/errors.go +102 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/principal_record.go +21 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/product_context.go +486 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/resource.go +215 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/resource_test.go +242 -0
- package/dist/resources/templates/go-backend/internal/products/README.md +5 -0
- package/dist/resources/templates/go-backend/internal/sharedevents/README.md +5 -0
- package/dist/resources/templates/go-backend/migrations/000001_infrastructure.down.sql +13 -0
- package/dist/resources/templates/go-backend/migrations/000001_infrastructure.up.sql +886 -0
- package/dist/resources/templates/go-backend/pkg/apierror/error.go +327 -0
- package/dist/resources/templates/go-backend/pkg/apierror/error_code.go +65 -0
- package/dist/resources/templates/go-backend/pkg/apierror/error_test.go +41 -0
- package/dist/resources/templates/go-backend/pkg/apierror/error_type.go +14 -0
- package/dist/resources/templates/go-backend/pkg/apierror/http_response.go +216 -0
- package/dist/resources/templates/go-backend/pkg/apierror/http_response_test.go +216 -0
- package/dist/resources/templates/go-backend/scripts/check-openapi-clean-deletion.sh +54 -0
- package/dist/resources/templates/go-backend/scripts/test-migrations.sh +32 -0
- package/dist/resources/templates/go-backend/tests/infrastructure.sql +69 -0
- package/dist/resources/templates/mcp-server/.claude/docs/stack.md +338 -0
- package/dist/resources/templates/mcp-server/.editorconfig +13 -0
- package/dist/resources/templates/mcp-server/.env.example +8 -0
- package/dist/resources/templates/mcp-server/.github/ISSUE_TEMPLATE/bug_report.yml +104 -0
- package/dist/resources/templates/mcp-server/.github/ISSUE_TEMPLATE/feature_request.yml +54 -0
- package/dist/resources/templates/mcp-server/.github/PULL_REQUEST_TEMPLATE.md +36 -0
- package/dist/resources/templates/mcp-server/.github/workflows/ci.yml +78 -0
- package/dist/resources/templates/mcp-server/.husky/commit-msg +1 -0
- package/dist/resources/templates/mcp-server/.husky/pre-commit +1 -0
- package/dist/resources/templates/mcp-server/.lintstagedrc.json +4 -0
- package/dist/resources/templates/mcp-server/.nvmrc +1 -0
- package/dist/resources/templates/mcp-server/.prettierrc +8 -0
- package/dist/resources/templates/mcp-server/CONTRIBUTING.md +184 -0
- package/dist/resources/templates/mcp-server/Dockerfile +23 -0
- package/dist/resources/templates/mcp-server/LICENSE +21 -0
- package/dist/resources/templates/mcp-server/README.md +123 -0
- package/dist/resources/templates/mcp-server/_gitignore +26 -0
- package/dist/resources/templates/mcp-server/commitlint.config.js +24 -0
- package/dist/resources/templates/mcp-server/eslint.config.js +30 -0
- package/dist/resources/templates/mcp-server/package.json +72 -0
- package/dist/resources/templates/mcp-server/src/index.ts +27 -0
- package/dist/resources/templates/mcp-server/src/resources.ts +33 -0
- package/dist/resources/templates/mcp-server/src/services/.gitkeep +0 -0
- package/dist/resources/templates/mcp-server/src/tools.ts +43 -0
- package/dist/resources/templates/mcp-server/src/types/index.ts +19 -0
- package/dist/resources/templates/mcp-server/src/utils/index.ts +31 -0
- package/dist/resources/templates/mcp-server/tsconfig.json +22 -0
- package/dist/resources/templates/mcp-server/tsup.config.ts +14 -0
- package/dist/resources/templates/mcp-server/vitest.config.ts +15 -0
- package/dist/resources/templates/nuxt/.claude/docs/stack.md +666 -0
- package/dist/resources/templates/nuxt/.editorconfig +15 -0
- package/dist/resources/templates/nuxt/.env.example +22 -0
- package/dist/resources/templates/nuxt/.github/workflows/ci.yml +34 -0
- package/dist/resources/templates/nuxt/.husky/commit-msg +1 -0
- package/dist/resources/templates/nuxt/.husky/pre-commit +1 -0
- package/dist/resources/templates/nuxt/.nvmrc +1 -0
- package/dist/resources/templates/nuxt/.prettierignore +9 -0
- package/dist/resources/templates/nuxt/.prettierrc +1 -0
- package/dist/resources/templates/nuxt/README.md +23 -0
- package/dist/resources/templates/nuxt/_gitignore +7 -0
- package/dist/resources/templates/nuxt/app/app.config.ts +105 -0
- package/dist/resources/templates/nuxt/app/i18n/locales/en.json +5 -0
- package/dist/resources/templates/nuxt/app/pages/app/index.vue +224 -0
- package/dist/resources/templates/nuxt/app/pages/authors/[slug].vue +37 -0
- package/dist/resources/templates/nuxt/app/pages/blog/[slug].vue +55 -0
- package/dist/resources/templates/nuxt/app/pages/blog/category/[category].vue +38 -0
- package/dist/resources/templates/nuxt/app/pages/blog/index.vue +46 -0
- package/dist/resources/templates/nuxt/app/pages/index.vue +626 -0
- package/dist/resources/templates/nuxt/app/pages/legal/privacy.vue +21 -0
- package/dist/resources/templates/nuxt/app/pages/legal/terms.vue +21 -0
- package/dist/resources/templates/nuxt/app/pages/ui/index.vue +397 -0
- package/dist/resources/templates/nuxt/commitlint.config.mjs +1 -0
- package/dist/resources/templates/nuxt/eslint.config.mjs +4 -0
- package/dist/resources/templates/nuxt/lint-staged.config.mjs +8 -0
- package/dist/resources/templates/nuxt/nuxt.config.ts +71 -0
- package/dist/resources/templates/nuxt/package.json +67 -0
- package/dist/resources/templates/nuxt/public/apple-touch-icon.png +0 -0
- package/dist/resources/templates/nuxt/public/favicon.ico +0 -0
- package/dist/resources/templates/nuxt/public/favicon.svg +5 -0
- package/dist/resources/templates/nuxt/public/icon-16x16.png +0 -0
- package/dist/resources/templates/nuxt/public/icon-192x192.png +0 -0
- package/dist/resources/templates/nuxt/public/icon-32x32.png +0 -0
- package/dist/resources/templates/nuxt/public/icon-512x512.png +0 -0
- package/dist/resources/templates/nuxt/public/logo.svg +6 -0
- package/dist/resources/templates/nuxt/public/media/hero-product-gallery.png +0 -0
- package/dist/resources/templates/nuxt/server/api/content/sitemap-urls.get.ts +12 -0
- package/dist/resources/templates/nuxt/server/api/preview.get.ts +9 -0
- package/dist/resources/templates/nuxt/stylelint.config.mjs +3 -0
- package/dist/resources/templates/nuxt/test/e2e/rendering.test.ts +13 -0
- package/dist/resources/templates/nuxt/tsconfig.json +3 -0
- package/dist/resources/templates/nuxt/vitest.config.ts +8 -0
- package/package.json +8 -5
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
package money
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"errors"
|
|
5
|
+
"testing"
|
|
6
|
+
|
|
7
|
+
"github.com/stretchr/testify/assert"
|
|
8
|
+
"github.com/stretchr/testify/require"
|
|
9
|
+
|
|
10
|
+
"{{module}}/internal/common/types"
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
// ─── FormatMajorOrZero (兜底版) — banker's rounding 边界全覆盖 ───
|
|
14
|
+
|
|
15
|
+
func TestFormatMajorOrZero(t *testing.T) {
|
|
16
|
+
tests := []struct {
|
|
17
|
+
name string
|
|
18
|
+
amount string
|
|
19
|
+
currency string
|
|
20
|
+
want string
|
|
21
|
+
}{
|
|
22
|
+
// USD - 2 位精度
|
|
23
|
+
{"USD 截断尾零", "9.9900", "USD", "9.99"},
|
|
24
|
+
{"USD 整数", "10", "USD", "10.00"},
|
|
25
|
+
{"USD 零", "0", "USD", "0.00"},
|
|
26
|
+
|
|
27
|
+
// USD banker's rounding (HALF_EVEN)
|
|
28
|
+
{"USD HalfEven 0.005 → 0.00", "0.005", "USD", "0.00"},
|
|
29
|
+
{"USD HalfEven 0.015 → 0.02", "0.015", "USD", "0.02"},
|
|
30
|
+
{"USD HalfEven 0.025 → 0.02", "0.025", "USD", "0.02"},
|
|
31
|
+
{"USD HalfEven 0.035 → 0.04", "0.035", "USD", "0.04"},
|
|
32
|
+
{"USD HalfEven 1.005 → 1.00", "1.005", "USD", "1.00"},
|
|
33
|
+
{"USD HalfEven 1.015 → 1.02", "1.015", "USD", "1.02"},
|
|
34
|
+
{"USD HalfEven 大于半数仍向上", "1.006", "USD", "1.01"},
|
|
35
|
+
{"USD HalfEven 小于半数仍向下", "1.004", "USD", "1.00"},
|
|
36
|
+
|
|
37
|
+
// USD 负数 banker's rounding
|
|
38
|
+
{"USD 负数尾零", "-9.9900", "USD", "-9.99"},
|
|
39
|
+
{"USD 负数 -0.005 → 0.00", "-0.005", "USD", "0.00"},
|
|
40
|
+
{"USD 负数 -0.015 → -0.02", "-0.015", "USD", "-0.02"},
|
|
41
|
+
{"USD 负数 -0.025 → -0.02", "-0.025", "USD", "-0.02"},
|
|
42
|
+
|
|
43
|
+
// USD 大额
|
|
44
|
+
{"USD 大额", "1234567890.1234", "USD", "1234567890.12"},
|
|
45
|
+
|
|
46
|
+
// JPY - 0 位精度
|
|
47
|
+
{"JPY 整数", "1999", "JPY", "1999"},
|
|
48
|
+
{"JPY HalfEven 1999.5 → 2000", "1999.5", "JPY", "2000"},
|
|
49
|
+
{"JPY HalfEven 2000.5 → 2000", "2000.5", "JPY", "2000"},
|
|
50
|
+
{"JPY HalfEven 2001.5 → 2002", "2001.5", "JPY", "2002"},
|
|
51
|
+
{"JPY 零", "0", "JPY", "0"},
|
|
52
|
+
{"JPY 整数尾零", "1999.0000", "JPY", "1999"},
|
|
53
|
+
{"JPY 截断小数大于半数", "1999.7", "JPY", "2000"},
|
|
54
|
+
|
|
55
|
+
// BHD - 3 位精度
|
|
56
|
+
{"BHD 截断到 3 位", "19.9999", "BHD", "20.000"},
|
|
57
|
+
{"BHD 保留 3 位", "19.123", "BHD", "19.123"},
|
|
58
|
+
{"BHD HalfEven 0.0005 → 0.000", "0.0005", "BHD", "0.000"},
|
|
59
|
+
{"BHD HalfEven 0.0015 → 0.002", "0.0015", "BHD", "0.002"},
|
|
60
|
+
|
|
61
|
+
// 边界
|
|
62
|
+
{"空字符串 USD", "", "USD", "0.00"},
|
|
63
|
+
{"空字符串 JPY", "", "JPY", "0"},
|
|
64
|
+
{"空字符串 BHD", "", "BHD", "0.000"},
|
|
65
|
+
{"空字符串未知货币", "", "XYZ", "0.00"},
|
|
66
|
+
|
|
67
|
+
// 未知货币 fallback 2 位
|
|
68
|
+
{"未知货币", "9.9900", "XYZ", "9.99"},
|
|
69
|
+
{"小写货币代码", "9.9900", "usd", "9.99"},
|
|
70
|
+
|
|
71
|
+
// 解析失败 fail-closed → 零
|
|
72
|
+
{"非法 decimal USD", "abc", "USD", "0.00"},
|
|
73
|
+
{"非法 decimal JPY", "1.2.3", "JPY", "0"},
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
for _, tc := range tests {
|
|
77
|
+
t.Run(tc.name, func(t *testing.T) {
|
|
78
|
+
got := FormatMajorOrZero(tc.amount, tc.currency)
|
|
79
|
+
assert.Equal(t, tc.want, got)
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
func TestFormatMajorWithCurrencySymbolOrZero(t *testing.T) {
|
|
85
|
+
bhdMeta, ok := types.LookupCurrencyMeta("BHD")
|
|
86
|
+
require.True(t, ok)
|
|
87
|
+
|
|
88
|
+
tests := []struct {
|
|
89
|
+
name string
|
|
90
|
+
amount string
|
|
91
|
+
currency string
|
|
92
|
+
want string
|
|
93
|
+
}{
|
|
94
|
+
{"USD trims storage scale", "29.9900", "USD", "$29.99"},
|
|
95
|
+
{"JPY uses zero decimals", "1999.0000", "JPY", "¥1999"},
|
|
96
|
+
{"BHD uses three decimals", "1.2345", "BHD", bhdMeta.Symbol + "1.234"},
|
|
97
|
+
{"unknown currency keeps code", "9.9900", "xyz", "XYZ9.99"},
|
|
98
|
+
{"empty currency omits symbol", "9.9900", "", "9.99"},
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
for _, tc := range tests {
|
|
102
|
+
t.Run(tc.name, func(t *testing.T) {
|
|
103
|
+
got := FormatMajorWithCurrencySymbolOrZero(tc.amount, tc.currency)
|
|
104
|
+
assert.Equal(t, tc.want, got)
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ─── FormatMajor (严格版) — 错误传递 ─────────────────────────────
|
|
110
|
+
|
|
111
|
+
func TestFormatMajor(t *testing.T) {
|
|
112
|
+
t.Run("正常路径", func(t *testing.T) {
|
|
113
|
+
got, err := FormatMajor("9.9900", "USD")
|
|
114
|
+
require.NoError(t, err)
|
|
115
|
+
assert.Equal(t, "9.99", got)
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
t.Run("空字符串返回 ErrEmptyAmount", func(t *testing.T) {
|
|
119
|
+
_, err := FormatMajor("", "USD")
|
|
120
|
+
require.Error(t, err)
|
|
121
|
+
assert.True(t, errors.Is(err, ErrEmptyAmount))
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
t.Run("非法 decimal 返回 ErrInvalidAmount", func(t *testing.T) {
|
|
125
|
+
_, err := FormatMajor("abc", "USD")
|
|
126
|
+
require.Error(t, err)
|
|
127
|
+
assert.True(t, errors.Is(err, ErrInvalidAmount))
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
t.Run("多个小数点返回 ErrInvalidAmount", func(t *testing.T) {
|
|
131
|
+
_, err := FormatMajor("1.2.3", "USD")
|
|
132
|
+
require.Error(t, err)
|
|
133
|
+
assert.True(t, errors.Is(err, ErrInvalidAmount))
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
t.Run("JPY 0 位精度", func(t *testing.T) {
|
|
137
|
+
got, err := FormatMajor("1999.5", "JPY")
|
|
138
|
+
require.NoError(t, err)
|
|
139
|
+
assert.Equal(t, "2000", got)
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
t.Run("BHD 3 位精度", func(t *testing.T) {
|
|
143
|
+
got, err := FormatMajor("19.9999", "BHD")
|
|
144
|
+
require.NoError(t, err)
|
|
145
|
+
assert.Equal(t, "20.000", got)
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
t.Run("未知货币兜底 2 位精度(不报错)", func(t *testing.T) {
|
|
149
|
+
got, err := FormatMajor("9.9900", "XYZ")
|
|
150
|
+
require.NoError(t, err)
|
|
151
|
+
assert.Equal(t, "9.99", got)
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// ─── FormatMajorPtrOrZero / FormatMajorPtrsOrZero (兜底版) ──────
|
|
156
|
+
|
|
157
|
+
func TestFormatMajorPtrOrZero(t *testing.T) {
|
|
158
|
+
t.Run("nil 透传 nil", func(t *testing.T) {
|
|
159
|
+
assert.Nil(t, FormatMajorPtrOrZero(nil, "USD"))
|
|
160
|
+
})
|
|
161
|
+
t.Run("非 nil 正常格式化", func(t *testing.T) {
|
|
162
|
+
amount := "9.9900"
|
|
163
|
+
got := FormatMajorPtrOrZero(&amount, "USD")
|
|
164
|
+
require.NotNil(t, got)
|
|
165
|
+
assert.Equal(t, "9.99", *got)
|
|
166
|
+
})
|
|
167
|
+
t.Run("非 nil JPY", func(t *testing.T) {
|
|
168
|
+
amount := "1999.50"
|
|
169
|
+
got := FormatMajorPtrOrZero(&amount, "JPY")
|
|
170
|
+
require.NotNil(t, got)
|
|
171
|
+
assert.Equal(t, "2000", *got)
|
|
172
|
+
})
|
|
173
|
+
t.Run("非 nil 解析失败兜底零值", func(t *testing.T) {
|
|
174
|
+
amount := "abc"
|
|
175
|
+
got := FormatMajorPtrOrZero(&amount, "USD")
|
|
176
|
+
require.NotNil(t, got)
|
|
177
|
+
assert.Equal(t, "0.00", *got)
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
func TestFormatMajorPtrsOrZero(t *testing.T) {
|
|
182
|
+
usd := "USD"
|
|
183
|
+
amount := "9.9900"
|
|
184
|
+
t.Run("amount nil 透传", func(t *testing.T) {
|
|
185
|
+
assert.Nil(t, FormatMajorPtrsOrZero(nil, &usd))
|
|
186
|
+
})
|
|
187
|
+
t.Run("currency nil 透传", func(t *testing.T) {
|
|
188
|
+
assert.Nil(t, FormatMajorPtrsOrZero(&amount, nil))
|
|
189
|
+
})
|
|
190
|
+
t.Run("两者 nil 透传", func(t *testing.T) {
|
|
191
|
+
assert.Nil(t, FormatMajorPtrsOrZero(nil, nil))
|
|
192
|
+
})
|
|
193
|
+
t.Run("两者非 nil 格式化", func(t *testing.T) {
|
|
194
|
+
got := FormatMajorPtrsOrZero(&amount, &usd)
|
|
195
|
+
require.NotNil(t, got)
|
|
196
|
+
assert.Equal(t, "9.99", *got)
|
|
197
|
+
})
|
|
198
|
+
t.Run("解析失败兜底零值", func(t *testing.T) {
|
|
199
|
+
bad := "abc"
|
|
200
|
+
got := FormatMajorPtrsOrZero(&bad, &usd)
|
|
201
|
+
require.NotNil(t, got)
|
|
202
|
+
assert.Equal(t, "0.00", *got)
|
|
203
|
+
})
|
|
204
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
package money
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"fmt"
|
|
5
|
+
"math"
|
|
6
|
+
"math/big"
|
|
7
|
+
"strings"
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
// MinorToMajor 将最小货币单位转换为主要单位字符串。
|
|
11
|
+
//
|
|
12
|
+
// 根据货币的 DecimalPlaces 自动选择除数:
|
|
13
|
+
// - USD (2位): 1999 → "19.99"
|
|
14
|
+
// - JPY (0位): 1999 → "1999"
|
|
15
|
+
// - BHD (3位): 19990 → "19.990"
|
|
16
|
+
//
|
|
17
|
+
// 用于支付网关响应解码(Stripe / Airwallex 把金额以最小单位整数返回)。
|
|
18
|
+
//
|
|
19
|
+
// 命名与 Stripe / moneyphp 行业术语对齐;不返回 error,未知货币按 2 位精度
|
|
20
|
+
// 兜底,调用方需保证 currency 合法。
|
|
21
|
+
func MinorToMajor(minorUnit int64, currencyCode string) string {
|
|
22
|
+
dp := DecimalPlaces(currencyCode)
|
|
23
|
+
if dp == 0 {
|
|
24
|
+
return fmt.Sprintf("%d", minorUnit)
|
|
25
|
+
}
|
|
26
|
+
divisor := int64(math.Pow10(dp))
|
|
27
|
+
whole := minorUnit / divisor
|
|
28
|
+
frac := minorUnit % divisor
|
|
29
|
+
if frac < 0 {
|
|
30
|
+
frac = -frac
|
|
31
|
+
}
|
|
32
|
+
return fmt.Sprintf("%d.%0*d", whole, dp, frac)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// MajorToMinor 将主要货币单位字符串转换为最小货币单位。
|
|
36
|
+
//
|
|
37
|
+
// 根据货币的 DecimalPlaces 自动选择乘数:
|
|
38
|
+
// - USD (2位): "19.99" → 1999
|
|
39
|
+
// - JPY (0位): "1999" → 1999(不乘)
|
|
40
|
+
// - BHD (3位): "19.990" → 19990
|
|
41
|
+
//
|
|
42
|
+
// 用于支付网关请求编码(金额必须以最小单位整数发送给 Stripe / Airwallex)。
|
|
43
|
+
//
|
|
44
|
+
// 错误条件:
|
|
45
|
+
// - amount 为空 / 不匹配严格十进制正则 → ErrInvalidAmount(拒绝 "5e9999" /
|
|
46
|
+
// "0x10" / "+5" 等非财务格式,与 Stripe API、Java BigDecimal(String) 一致)
|
|
47
|
+
// - amount 整数部分非法 → ErrInvalidAmount
|
|
48
|
+
// - amount 小数部分非法 → ErrInvalidAmount
|
|
49
|
+
// - amount 小数位数超出货币精度 → ErrInvalidAmount(与 Stripe API 一致,
|
|
50
|
+
// 拒绝 fractional minor unit;如 USD "9.999" 不能编码为 999.9 美分)
|
|
51
|
+
//
|
|
52
|
+
// 注:`MajorToMinor` 是网关编码入口(fail-loud),与 `FromMajor` 的展示路径
|
|
53
|
+
// 截断行为不同 —— 后者用于内部 Money 构造,超出精度按截断处理是合理的展示
|
|
54
|
+
// 兜底;前者要发送给真实支付网关,必须严格拒绝精度溢出,否则会丢失用户金额。
|
|
55
|
+
func MajorToMinor(amount, currencyCode string) (int64, error) {
|
|
56
|
+
return majorToMinor(amount, DecimalPlaces(currencyCode), currencyCode)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// MajorToMinorWithExponent 使用已锁定的货币指数将主要单位转换为最小单位。
|
|
60
|
+
// 调用方必须从成交或价格快照读取指数,不能在消费边界按币种再次推断。
|
|
61
|
+
func MajorToMinorWithExponent(amount string, exponent int) (int64, error) {
|
|
62
|
+
if exponent < 0 || exponent > 18 {
|
|
63
|
+
return 0, fmt.Errorf("%w: currency exponent %d is outside [0,18]", ErrInvalidAmount, exponent)
|
|
64
|
+
}
|
|
65
|
+
return majorToMinor(amount, exponent, fmt.Sprintf("exponent:%d", exponent))
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
func majorToMinor(amount string, dp int, precisionOwner string) (int64, error) {
|
|
69
|
+
multiplier := int64(math.Pow10(dp))
|
|
70
|
+
|
|
71
|
+
// 严格十进制前置校验:复用 format.go 的 strictDecimalRe,避免 big.Int.SetString
|
|
72
|
+
// 接受 "+5" / 空字符串等非财务格式(与下方 SplitN("", ".", 2) 配合时,
|
|
73
|
+
// "" 会被解析为单元素切片导致后续逻辑出错;负号检查也会越界)。
|
|
74
|
+
if !strictDecimalRe.MatchString(amount) {
|
|
75
|
+
return 0, fmt.Errorf("%w: %q", ErrInvalidAmount, amount)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
parts := strings.SplitN(amount, ".", 2)
|
|
79
|
+
negative := strings.HasPrefix(amount, "-")
|
|
80
|
+
|
|
81
|
+
intStr := parts[0]
|
|
82
|
+
if negative {
|
|
83
|
+
intStr = intStr[1:]
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
integerPart := new(big.Int)
|
|
87
|
+
if _, ok := integerPart.SetString(intStr, 10); !ok {
|
|
88
|
+
return 0, fmt.Errorf("%w: %s", ErrInvalidAmount, amount)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
result := new(big.Int).Mul(integerPart, big.NewInt(multiplier))
|
|
92
|
+
|
|
93
|
+
if len(parts) == 2 {
|
|
94
|
+
fracStr := parts[1]
|
|
95
|
+
// 拒绝精度溢出:USD 只支持 2 位小数,"9.999" 无法表达为整数美分。
|
|
96
|
+
// 例外:超出精度的部分如果全是零,可以容忍("1999.0" 当 JPY 处理)。
|
|
97
|
+
if len(fracStr) > dp {
|
|
98
|
+
overflow := fracStr[dp:]
|
|
99
|
+
fp := new(big.Int)
|
|
100
|
+
if _, ok := fp.SetString(overflow, 10); !ok {
|
|
101
|
+
return 0, fmt.Errorf("%w: invalid fractional part %q", ErrInvalidAmount, overflow)
|
|
102
|
+
}
|
|
103
|
+
if fp.Sign() != 0 {
|
|
104
|
+
return 0, fmt.Errorf("%w: amount %q exceeds %s precision (%d decimal places)",
|
|
105
|
+
ErrInvalidAmount, amount, precisionOwner, dp)
|
|
106
|
+
}
|
|
107
|
+
fracStr = fracStr[:dp]
|
|
108
|
+
}
|
|
109
|
+
if dp > 0 {
|
|
110
|
+
for len(fracStr) < dp {
|
|
111
|
+
fracStr += "0"
|
|
112
|
+
}
|
|
113
|
+
fp := new(big.Int)
|
|
114
|
+
if _, ok := fp.SetString(fracStr, 10); !ok {
|
|
115
|
+
return 0, fmt.Errorf("%w: invalid fractional part %q", ErrInvalidAmount, fracStr)
|
|
116
|
+
}
|
|
117
|
+
result.Add(result, fp)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if negative {
|
|
122
|
+
result.Neg(result)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if !result.IsInt64() {
|
|
126
|
+
return 0, fmt.Errorf("%w: amount %q exceeds int64 minor-unit range", ErrInvalidAmount, amount)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return result.Int64(), nil
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// FormatMajorFromFloat 将 float64 金额按货币精度格式化为字符串。
|
|
133
|
+
//
|
|
134
|
+
// 根据货币的 DecimalPlaces 自动决定小数位数:
|
|
135
|
+
// - USD (2位): 19.99 → "19.99"
|
|
136
|
+
// - JPY (0位): 1999.0 → "1999"
|
|
137
|
+
// - BHD (3位): 19.99 → "19.990"
|
|
138
|
+
//
|
|
139
|
+
// 用于网关返回 float 金额的展示路径(Airwallex / Apple IAP)。
|
|
140
|
+
// 不返回 error;未知货币按 2 位精度兜底。
|
|
141
|
+
func FormatMajorFromFloat(amount float64, currencyCode string) string {
|
|
142
|
+
dp := DecimalPlaces(currencyCode)
|
|
143
|
+
return fmt.Sprintf("%.*f", dp, amount)
|
|
144
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
package money
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"errors"
|
|
5
|
+
"math"
|
|
6
|
+
"testing"
|
|
7
|
+
|
|
8
|
+
"github.com/stretchr/testify/assert"
|
|
9
|
+
"github.com/stretchr/testify/require"
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
// ─── MinorToMajor ────────────────────────────────────────────────
|
|
13
|
+
|
|
14
|
+
func TestMinorToMajor(t *testing.T) {
|
|
15
|
+
tests := []struct {
|
|
16
|
+
name string
|
|
17
|
+
minorUnit int64
|
|
18
|
+
currencyCode string
|
|
19
|
+
want string
|
|
20
|
+
}{
|
|
21
|
+
{"USD 美元", 1999, "USD", "19.99"},
|
|
22
|
+
{"USD 整数美元", 100, "USD", "1.00"},
|
|
23
|
+
{"USD 不足 1 美元", 1, "USD", "0.01"},
|
|
24
|
+
{"USD 零", 0, "USD", "0.00"},
|
|
25
|
+
{"USD 大额", 123456789, "USD", "1234567.89"},
|
|
26
|
+
|
|
27
|
+
{"JPY 无小数", 1999, "JPY", "1999"},
|
|
28
|
+
{"JPY 零", 0, "JPY", "0"},
|
|
29
|
+
|
|
30
|
+
{"BHD 三位小数", 19990, "BHD", "19.990"},
|
|
31
|
+
{"BHD 不足 1 BHD", 1, "BHD", "0.001"},
|
|
32
|
+
|
|
33
|
+
{"未知货币兜底 2 位", 1999, "XYZ", "19.99"},
|
|
34
|
+
|
|
35
|
+
{"负数 USD", -1999, "USD", "-19.99"},
|
|
36
|
+
{"负数 JPY", -1999, "JPY", "-1999"},
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
for _, tc := range tests {
|
|
40
|
+
t.Run(tc.name, func(t *testing.T) {
|
|
41
|
+
got := MinorToMajor(tc.minorUnit, tc.currencyCode)
|
|
42
|
+
assert.Equal(t, tc.want, got)
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ─── MajorToMinor ────────────────────────────────────────────────
|
|
48
|
+
|
|
49
|
+
func TestMajorToMinor(t *testing.T) {
|
|
50
|
+
tests := []struct {
|
|
51
|
+
name string
|
|
52
|
+
amount string
|
|
53
|
+
currencyCode string
|
|
54
|
+
want int64
|
|
55
|
+
wantErr bool
|
|
56
|
+
}{
|
|
57
|
+
{"USD 19.99 → 1999", "19.99", "USD", 1999, false},
|
|
58
|
+
{"USD 整数", "100", "USD", 10000, false},
|
|
59
|
+
{"USD 零", "0", "USD", 0, false},
|
|
60
|
+
{"USD 负数", "-5.50", "USD", -550, false},
|
|
61
|
+
{"USD int64 最大值", "92233720368547758.07", "USD", math.MaxInt64, false},
|
|
62
|
+
{"USD int64 最小值", "-92233720368547758.08", "USD", math.MinInt64, false},
|
|
63
|
+
{"USD 拒绝正向溢出", "92233720368547758.08", "USD", 0, true},
|
|
64
|
+
{"USD 拒绝负向溢出", "-92233720368547758.09", "USD", 0, true},
|
|
65
|
+
// 网关编码入口(fail-loud):精度超出必须拒绝,与 Stripe API 一致
|
|
66
|
+
{"USD 拒绝精度溢出", "10.999", "USD", 0, true},
|
|
67
|
+
{"USD 拒绝多位精度溢出", "10.12345", "USD", 0, true},
|
|
68
|
+
|
|
69
|
+
{"JPY 整数", "1999", "JPY", 1999, false},
|
|
70
|
+
{"JPY 整数带 .0 容忍", "1999.0", "JPY", 1999, false},
|
|
71
|
+
{"JPY 拒绝小数", "1999.9", "JPY", 0, true},
|
|
72
|
+
{"JPY int64 最大值", "9223372036854775807", "JPY", math.MaxInt64, false},
|
|
73
|
+
{"JPY int64 最小值", "-9223372036854775808", "JPY", math.MinInt64, false},
|
|
74
|
+
{"JPY 拒绝正向溢出", "9223372036854775808", "JPY", 0, true},
|
|
75
|
+
{"JPY 拒绝负向溢出", "-9223372036854775809", "JPY", 0, true},
|
|
76
|
+
|
|
77
|
+
{"BHD 三位小数", "19.990", "BHD", 19990, false},
|
|
78
|
+
{"BHD int64 最大值", "9223372036854775.807", "BHD", math.MaxInt64, false},
|
|
79
|
+
{"BHD int64 最小值", "-9223372036854775.808", "BHD", math.MinInt64, false},
|
|
80
|
+
{"BHD 拒绝正向溢出", "9223372036854775.808", "BHD", 0, true},
|
|
81
|
+
{"BHD 拒绝负向溢出", "-9223372036854775.809", "BHD", 0, true},
|
|
82
|
+
// 超出精度但全为零 → 容忍("19.9990" 等价于 "19.999")
|
|
83
|
+
{"BHD 多位尾零容忍", "19.9990", "BHD", 19999, false},
|
|
84
|
+
// 超出精度且有非零位 → 拒绝
|
|
85
|
+
{"BHD 拒绝四位精度溢出", "19.9999", "BHD", 0, true},
|
|
86
|
+
|
|
87
|
+
{"非法整数部分", "abc.00", "USD", 0, true},
|
|
88
|
+
{"完全非法", "abc", "USD", 0, true},
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
for _, tc := range tests {
|
|
92
|
+
t.Run(tc.name, func(t *testing.T) {
|
|
93
|
+
got, err := MajorToMinor(tc.amount, tc.currencyCode)
|
|
94
|
+
if tc.wantErr {
|
|
95
|
+
require.Error(t, err)
|
|
96
|
+
assert.True(t, errors.Is(err, ErrInvalidAmount))
|
|
97
|
+
} else {
|
|
98
|
+
require.NoError(t, err)
|
|
99
|
+
assert.Equal(t, tc.want, got)
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
func TestMajorToMinorWithExponentUsesSnapshottedPrecision(t *testing.T) {
|
|
106
|
+
minor, err := MajorToMinorWithExponent("1.234", 3)
|
|
107
|
+
require.NoError(t, err)
|
|
108
|
+
assert.Equal(t, int64(1234), minor)
|
|
109
|
+
|
|
110
|
+
_, err = MajorToMinorWithExponent("1.234", 2)
|
|
111
|
+
require.Error(t, err)
|
|
112
|
+
assert.True(t, errors.Is(err, ErrInvalidAmount))
|
|
113
|
+
|
|
114
|
+
_, err = MajorToMinorWithExponent("1", 19)
|
|
115
|
+
require.Error(t, err)
|
|
116
|
+
assert.True(t, errors.Is(err, ErrInvalidAmount))
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ─── 双向往返一致性 ──────────────────────────────────────────────
|
|
120
|
+
|
|
121
|
+
func TestMinorMajorRoundTrip(t *testing.T) {
|
|
122
|
+
cases := []struct {
|
|
123
|
+
minor int64
|
|
124
|
+
currency string
|
|
125
|
+
}{
|
|
126
|
+
{1999, "USD"},
|
|
127
|
+
{100, "USD"},
|
|
128
|
+
{0, "USD"},
|
|
129
|
+
{1999, "JPY"},
|
|
130
|
+
{19990, "BHD"},
|
|
131
|
+
}
|
|
132
|
+
for _, c := range cases {
|
|
133
|
+
major := MinorToMajor(c.minor, c.currency)
|
|
134
|
+
back, err := MajorToMinor(major, c.currency)
|
|
135
|
+
require.NoError(t, err)
|
|
136
|
+
assert.Equal(t, c.minor, back, "round trip mismatch for %d %s", c.minor, c.currency)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// ─── FormatMajorFromFloat ────────────────────────────────────────
|
|
141
|
+
|
|
142
|
+
func TestFormatMajorFromFloat(t *testing.T) {
|
|
143
|
+
tests := []struct {
|
|
144
|
+
name string
|
|
145
|
+
amount float64
|
|
146
|
+
currencyCode string
|
|
147
|
+
want string
|
|
148
|
+
}{
|
|
149
|
+
{"USD 2 位精度", 19.99, "USD", "19.99"},
|
|
150
|
+
{"USD 截断展示", 19.999, "USD", "20.00"},
|
|
151
|
+
{"JPY 0 位精度", 1999.0, "JPY", "1999"},
|
|
152
|
+
{"JPY 浮点输入截断", 1999.7, "JPY", "2000"},
|
|
153
|
+
{"BHD 3 位精度", 19.99, "BHD", "19.990"},
|
|
154
|
+
{"未知货币兜底 2 位", 19.99, "XYZ", "19.99"},
|
|
155
|
+
{"零", 0.0, "USD", "0.00"},
|
|
156
|
+
{"负数", -19.99, "USD", "-19.99"},
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
for _, tc := range tests {
|
|
160
|
+
t.Run(tc.name, func(t *testing.T) {
|
|
161
|
+
got := FormatMajorFromFloat(tc.amount, tc.currencyCode)
|
|
162
|
+
assert.Equal(t, tc.want, got)
|
|
163
|
+
})
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
package money
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"fmt"
|
|
5
|
+
|
|
6
|
+
"github.com/shopspring/decimal"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
// DivideMinorUnitsHalfEven 使用纯整数运算将最小货币单位按 HALF_EVEN 舍入相除。
|
|
10
|
+
// 支持正负金额;除数必须为正数。实现不对余数乘二,避免 int64 边界溢出。
|
|
11
|
+
func DivideMinorUnitsHalfEven(amountMinor, divisor int64) (int64, error) {
|
|
12
|
+
if divisor <= 0 {
|
|
13
|
+
return 0, fmt.Errorf("%w: %d", ErrInvalidDivisor, divisor)
|
|
14
|
+
}
|
|
15
|
+
quotient := amountMinor / divisor
|
|
16
|
+
remainder := amountMinor % divisor
|
|
17
|
+
if remainder == 0 {
|
|
18
|
+
return quotient, nil
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
direction := int64(1)
|
|
22
|
+
if remainder < 0 {
|
|
23
|
+
remainder = -remainder
|
|
24
|
+
direction = -1
|
|
25
|
+
}
|
|
26
|
+
complement := divisor - remainder
|
|
27
|
+
if remainder > complement || (remainder == complement && quotient%2 != 0) {
|
|
28
|
+
quotient += direction
|
|
29
|
+
}
|
|
30
|
+
return quotient, nil
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// formatDecimalBankerRounding 用 banker's rounding(HALF_EVEN)格式化金额。
|
|
34
|
+
func formatDecimalBankerRounding(value decimal.Decimal, dp int) string {
|
|
35
|
+
if dp < 0 {
|
|
36
|
+
dp = 0
|
|
37
|
+
}
|
|
38
|
+
return value.RoundBank(int32(dp)).StringFixed(int32(dp))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// zeroWithDecimals 返回指定小数位的零值字符串,如 (2 → "0.00"、0 → "0"、3 → "0.000")。
|
|
42
|
+
func zeroWithDecimals(dp int) string {
|
|
43
|
+
if dp <= 0 {
|
|
44
|
+
return "0"
|
|
45
|
+
}
|
|
46
|
+
return "0." + repeatZeros(dp)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// repeatZeros 生成 n 个 '0' 字符串,避免 strings.Repeat 在热点路径上的额外分配。
|
|
50
|
+
func repeatZeros(n int) string {
|
|
51
|
+
buf := make([]byte, n)
|
|
52
|
+
for i := range buf {
|
|
53
|
+
buf[i] = '0'
|
|
54
|
+
}
|
|
55
|
+
return string(buf)
|
|
56
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
package money
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"errors"
|
|
5
|
+
"math"
|
|
6
|
+
"testing"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
func TestDivideMinorUnitsHalfEven(t *testing.T) {
|
|
10
|
+
t.Parallel()
|
|
11
|
+
|
|
12
|
+
tests := []struct {
|
|
13
|
+
name string
|
|
14
|
+
amountMinor int64
|
|
15
|
+
divisor int64
|
|
16
|
+
want int64
|
|
17
|
+
}{
|
|
18
|
+
{name: "exact", amountMinor: 1200, divisor: 12, want: 100},
|
|
19
|
+
{name: "positive below half", amountMinor: 1000, divisor: 12, want: 83},
|
|
20
|
+
{name: "positive odd tie", amountMinor: 1002, divisor: 12, want: 84},
|
|
21
|
+
{name: "positive even tie", amountMinor: 1014, divisor: 12, want: 84},
|
|
22
|
+
{name: "negative odd tie", amountMinor: -1002, divisor: 12, want: -84},
|
|
23
|
+
{name: "negative even tie", amountMinor: -1014, divisor: 12, want: -84},
|
|
24
|
+
{name: "maximum int64", amountMinor: math.MaxInt64, divisor: 2, want: 4611686018427387904},
|
|
25
|
+
{name: "minimum int64", amountMinor: math.MinInt64, divisor: 3, want: -3074457345618258603},
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
for _, test := range tests {
|
|
29
|
+
t.Run(test.name, func(t *testing.T) {
|
|
30
|
+
t.Parallel()
|
|
31
|
+
got, err := DivideMinorUnitsHalfEven(test.amountMinor, test.divisor)
|
|
32
|
+
if err != nil {
|
|
33
|
+
t.Fatalf("DivideMinorUnitsHalfEven() error = %v", err)
|
|
34
|
+
}
|
|
35
|
+
if got != test.want {
|
|
36
|
+
t.Fatalf("DivideMinorUnitsHalfEven() = %d, want %d", got, test.want)
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
func TestDivideMinorUnitsHalfEvenRejectsNonPositiveDivisor(t *testing.T) {
|
|
43
|
+
t.Parallel()
|
|
44
|
+
|
|
45
|
+
for _, divisor := range []int64{0, -1} {
|
|
46
|
+
_, err := DivideMinorUnitsHalfEven(1000, divisor)
|
|
47
|
+
if !errors.Is(err, ErrInvalidDivisor) {
|
|
48
|
+
t.Fatalf("DivideMinorUnitsHalfEven() error = %v, want ErrInvalidDivisor", err)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
package principal
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
|
|
6
|
+
"github.com/gin-gonic/gin"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
// ctxKey 私有 context key 类型,避免与其他 package collision。
|
|
10
|
+
type ctxKey struct{}
|
|
11
|
+
|
|
12
|
+
// ginKey gin.Context 中的 key 名(使用与 ctx 解耦的字符串以方便跨 helper 读取)。
|
|
13
|
+
const ginKey = "principal"
|
|
14
|
+
|
|
15
|
+
// WithPrincipal 把 Principal 写入 context.Context(供 service 层读取)+ gin.Context(供 handler 读取)。
|
|
16
|
+
func WithPrincipal(c *gin.Context, p *Principal) {
|
|
17
|
+
c.Set(ginKey, p)
|
|
18
|
+
ctx := context.WithValue(c.Request.Context(), ctxKey{}, p)
|
|
19
|
+
c.Request = c.Request.WithContext(ctx)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Get 读取 Principal。未注入时返回 nil(公开路径 + 匿名访问场景)。
|
|
23
|
+
//
|
|
24
|
+
// 优先 gin.Context 路径(handler 用),fallback 到 context.Context(service 用)。
|
|
25
|
+
func Get(c *gin.Context) *Principal {
|
|
26
|
+
if v, ok := c.Get(ginKey); ok {
|
|
27
|
+
if p, ok := v.(*Principal); ok {
|
|
28
|
+
return p
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return FromContext(c.Request.Context())
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// FromContext 仅从 context.Context 读取(service 层调用,无 gin.Context)。
|
|
35
|
+
func FromContext(ctx context.Context) *Principal {
|
|
36
|
+
if ctx == nil {
|
|
37
|
+
return nil
|
|
38
|
+
}
|
|
39
|
+
v := ctx.Value(ctxKey{})
|
|
40
|
+
if p, ok := v.(*Principal); ok {
|
|
41
|
+
return p
|
|
42
|
+
}
|
|
43
|
+
return nil
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// MustGet 读取 Principal,未注入时 panic。
|
|
47
|
+
//
|
|
48
|
+
// 仅在已挂载 PrincipalContext middleware 的 authenticated 路由 handler 中使用。
|
|
49
|
+
// 公开路径请用 Get(nil-safe)。
|
|
50
|
+
func MustGet(c *gin.Context) *Principal {
|
|
51
|
+
p := Get(c)
|
|
52
|
+
if p == nil {
|
|
53
|
+
panic("principal: middleware.PrincipalContext not registered for this route")
|
|
54
|
+
}
|
|
55
|
+
return p
|
|
56
|
+
}
|