优化结构

This commit is contained in:
Yvan
2026-08-21 00:31:43 +08:00
parent d2fb5c11b8
commit c968f9f24e
8 changed files with 164 additions and 159 deletions
+3 -1
View File
@@ -8,7 +8,9 @@
- `module`:模块迁移、后台元数据和路由注册协议
- `task`:跨模块共享的进程内任务注册表和贡献协议
- `logging`:跨 app 复用的结构化日志能力
- `paymentkit`:支付金额、签名、状态和报文处理纯函数
- `httpx`:跨 HTTP 模块共享的 JSON 响应结构、分页结构和状态码
- `paymentkit`:支付金额、签名、状态、provider 标识和回调应答纯函数
- `protoutil`:与业务无关的 protobuf JSON 局部合并工具
`pkg` 只能提供机制和稳定协议,不能引用任何 `app/*/internal`。数据库配置加载、
系统集成配置、系统表和 provider 生命周期仍由 `app/system` 负责。
+33
View File
@@ -0,0 +1,33 @@
package httpx
import (
"net/http/httptest"
"testing"
"github.com/gin-gonic/gin"
)
func TestResponseHelpers(t *testing.T) {
gin.SetMode(gin.TestMode)
r := gin.New()
r.GET("/ok", OK)
r.GET("/fail", func(c *gin.Context) { Fail(c, "bad") })
r.GET("/auth", func(c *gin.Context) { NoAuth(c, "login") })
for _, tc := range []struct {
path string
statusCode int
body string
}{
{"/ok", 200, `{"code":0,"data":{},"msg":"操作成功"}`},
{"/fail", 200, `{"code":7,"data":{},"msg":"bad"}`},
{"/auth", 401, `{"code":7,"data":null,"msg":"login"}`},
} {
req := httptest.NewRequest("GET", tc.path, nil)
w := httptest.NewRecorder()
r.ServeHTTP(w, req)
if w.Code != tc.statusCode || w.Body.String() != tc.body {
t.Fatalf("%s: status=%d body=%q", tc.path, w.Code, w.Body.String())
}
}
}
-8
View File
@@ -6,14 +6,6 @@ import (
"fmt"
)
const (
ProviderAlipay = "alipay"
ProviderAlipayV3 = "alipay-v3"
ProviderWechatV2 = "wechat-v2"
ProviderWechatV3 = "wechat-v3"
ProviderApple = "apple-iap"
)
// CallbackAck is the provider-facing HTTP acknowledgement returned after a
// payment notification is processed.
type CallbackAck struct {
+36
View File
@@ -0,0 +1,36 @@
package paymentutil
const (
ProviderAlipay = "alipay"
ProviderAlipayV3 = "alipay-v3"
ProviderWechatV2 = "wechat-v2"
ProviderWechatV3 = "wechat-v3"
ProviderApple = "apple-iap"
ProviderChinaums = "chinaums"
ProviderSFT = "sft"
ProviderSuperPay = "supper-pay"
ProviderWechatGame = "wechat-game-pay"
ProviderDouyinGame = "douyin-game-pay"
ProviderDouyin = "douyin"
ProviderQQ = "qq"
ProviderAllinPay = "allinpay"
ProviderLakala = "lakala"
ProviderPayPal = "paypal"
ProviderSaobei = "saobei"
ProviderInternal = "internal"
ModeExternal = "external"
ModeInternal = "internal"
)
var externalProviders = [...]string{
ProviderAlipay, ProviderAlipayV3, ProviderWechatV2, ProviderWechatV3, ProviderApple,
ProviderChinaums, ProviderSFT, ProviderSuperPay, ProviderWechatGame, ProviderDouyinGame,
ProviderDouyin, ProviderQQ, ProviderAllinPay, ProviderLakala, ProviderPayPal, ProviderSaobei,
}
// SupportedProviders returns a copy so callers cannot mutate the process-wide
// provider catalog.
func SupportedProviders() []string {
return append([]string(nil), externalProviders[:]...)
}