refactor: 删除无人调用的死代码
This commit is contained in:
1 parent
6ba6e1907c
commit
568e83d4dc
12 files changed
+5
-74
No files matched your search
@@ -220,7 +220,7 @@ func TestCatalogProductImplementationLivesInNestedBoundedContext(t *testing.T) {
|
||||
})
|
||||
assertFileDeclaresFunctions(t, filepath.Join(domainRoot, "pricing.go"), []string{
|
||||
"NormalizeWholesalePrices", "NormalizeWholesalePricesForSKUs",
|
||||
"ResolveWholesaleUnitPrice", "ResolveWholesaleUnitPriceWithMatchQuantity", "ResolveWholesaleUnitPriceForSKU",
|
||||
"ResolveWholesaleUnitPrice", "ResolveWholesaleUnitPriceForSKU",
|
||||
})
|
||||
assertFileDeclaresFunctions(t, filepath.Join(domainRoot, "purchase_policy.go"), []string{
|
||||
"NormalizePurchaseType", "NormalizeFulfillmentType", "NormalizeStockDisplayMode",
|
||||
|
||||
@@ -182,12 +182,6 @@ func ResolveWholesaleUnitPrice(product *Product, baseUnitPrice decimal.Decimal,
|
||||
return resolveWholesaleUnitPrice(product, baseUnitPrice, 0, "", quantity, quantity)
|
||||
}
|
||||
|
||||
// ResolveWholesaleUnitPriceWithMatchQuantity 按 matchQuantity 判断批发档位,按 quantity 计算当前行优惠。
|
||||
// 商品存在多 SKU 时,批发门槛按同一商品总购买数判断,但每个订单行只计算自己的优惠金额。
|
||||
func ResolveWholesaleUnitPriceWithMatchQuantity(product *Product, baseUnitPrice decimal.Decimal, matchQuantity, quantity int) (unitPrice decimal.Decimal, discount decimal.Decimal, matched bool) {
|
||||
return resolveWholesaleUnitPrice(product, baseUnitPrice, 0, "", matchQuantity, quantity)
|
||||
}
|
||||
|
||||
// ResolveWholesaleUnitPriceForSKU 按指定 SKU 的批发价阶梯解析成交单价。
|
||||
func ResolveWholesaleUnitPriceForSKU(product *Product, baseUnitPrice decimal.Decimal, skuID uint, skuCode string, matchQuantity, quantity int) (unitPrice decimal.Decimal, discount decimal.Decimal, matched bool) {
|
||||
return resolveWholesaleUnitPrice(product, baseUnitPrice, skuID, skuCode, matchQuantity, quantity)
|
||||
|
||||
@@ -63,10 +63,6 @@ func ComposePlainTextMessage(title, body string) string {
|
||||
return title + "\n\n" + body
|
||||
}
|
||||
|
||||
func ComposeTelegramMessage(title, body string) string {
|
||||
return ComposePlainTextMessage(title, body)
|
||||
}
|
||||
|
||||
func JSONToMap(data jsonmap.JSON) map[string]interface{} {
|
||||
if data == nil {
|
||||
return map[string]interface{}{}
|
||||
|
||||
@@ -40,13 +40,6 @@ func New(db *gorm.DB, guestCredentialSecret string) *Store {
|
||||
return &Store{db: db, guestCredentialSecret: []byte(secret)}
|
||||
}
|
||||
|
||||
func (r *Store) bind(tx *gorm.DB) *Store {
|
||||
if tx == nil {
|
||||
return r
|
||||
}
|
||||
return &Store{db: tx, guestCredentialSecret: r.guestCredentialSecret}
|
||||
}
|
||||
|
||||
func (r *Store) withChildren(query *gorm.DB) *gorm.DB {
|
||||
return query.
|
||||
Where("orders.deleted_at IS NULL").
|
||||
|
||||
@@ -92,7 +92,7 @@ func TestRiskGateSerializesConcurrentGuestQuotaChecks(t *testing.T) {
|
||||
defer wg.Done()
|
||||
<-start
|
||||
err := store.db.Transaction(func(dbtx *gorm.DB) error {
|
||||
txStore := store.bind(dbtx)
|
||||
txStore := &Store{db: dbtx, guestCredentialSecret: store.guestCredentialSecret}
|
||||
if err := txStore.LockRiskKeys([]string{"guest:ip:1.2.3.4"}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -238,14 +238,6 @@ func ResolveChain(tokenID string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// IsSupportedTokenID 判断 token_id 是否已收录在内置映射表中。
|
||||
// 该表仅用于精确解析 chain,不再作为准入白名单:未收录但符合命名约定的 token_id
|
||||
// 同样可用,准入条件是 ResolveChain 能推导出非空 chain。
|
||||
func IsSupportedTokenID(tokenID string) bool {
|
||||
_, ok := supportedTokenChains[strings.ToLower(strings.TrimSpace(tokenID))]
|
||||
return ok
|
||||
}
|
||||
|
||||
var supportedTokenChains = map[string]string{
|
||||
"tron-trx": "tron",
|
||||
"tron-usdt": "tron",
|
||||
|
||||
@@ -189,9 +189,6 @@ func TestResolveChainSupportsBSCUSDC(t *testing.T) {
|
||||
if got := ResolveChain("bsc-usdc"); got != "bsc" {
|
||||
t.Fatalf("ResolveChain(bsc-usdc) = %q, want bsc", got)
|
||||
}
|
||||
if !IsSupportedTokenID("BSC-USDC") {
|
||||
t.Fatalf("IsSupportedTokenID should accept bsc-usdc case-insensitively")
|
||||
}
|
||||
}
|
||||
|
||||
// ResolveChain 对未收录的 token_id 按最后一个连字符切分,使 DujiaoPay 新增链或代币时
|
||||
|
||||
@@ -72,12 +72,6 @@ func ExtractCryptoWalletInfo(providerType, interactionMode string, payload jsonm
|
||||
}
|
||||
}
|
||||
|
||||
// ExtractUSDTWalletInfo 从 Payment.ProviderPayload 中提取 USDT 收款钱包地址和链上实付金额。
|
||||
func ExtractUSDTWalletInfo(providerType, interactionMode string, payload jsonmap.JSON) (address, chainAmount string) {
|
||||
info := ExtractCryptoWalletInfo(providerType, interactionMode, payload)
|
||||
return info.Address, info.ChainAmount
|
||||
}
|
||||
|
||||
func firstPayloadString(values ...string) string {
|
||||
for _, value := range values {
|
||||
if value != "" {
|
||||
|
||||
@@ -86,7 +86,8 @@ func TestExtractUSDTWalletInfo(t *testing.T) {
|
||||
}
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
gotAddr, gotAmount := ExtractUSDTWalletInfo(tc.providerType, tc.interactionMode, tc.payload)
|
||||
info := ExtractCryptoWalletInfo(tc.providerType, tc.interactionMode, tc.payload)
|
||||
gotAddr, gotAmount := info.Address, info.ChainAmount
|
||||
if gotAddr != tc.wantAddress {
|
||||
t.Errorf("address: got %q want %q", gotAddr, tc.wantAddress)
|
||||
}
|
||||
|
||||
@@ -23,10 +23,6 @@ func TestGoogleAuthSettingNormalizeValidateAndPublicConfig(t *testing.T) {
|
||||
if err := settingssecurity.ValidateGoogleAuthSetting(settingssecurity.GoogleAuthSetting{Enabled: true}); !errors.Is(err, settingssecurity.ErrGoogleAuthConfigInvalid) {
|
||||
t.Fatalf("missing client id error = %v", err)
|
||||
}
|
||||
public := settingssecurity.PublicGoogleAuthSetting(setting)
|
||||
if public["enabled"] != true || public["client_id"] != "client.apps.googleusercontent.com" {
|
||||
t.Fatalf("unexpected public config: %#v", public)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPatchGoogleAuthSettingPersistsNormalizedValue(t *testing.T) {
|
||||
|
||||
@@ -83,15 +83,6 @@ func MaskGoogleAuthSettingForAdmin(setting GoogleAuthSetting) jsonmap.JSON {
|
||||
return EncodeGoogleAuthSetting(setting)
|
||||
}
|
||||
|
||||
// PublicGoogleAuthSetting 返回前台初始化 Google Identity Services 所需的最小配置。
|
||||
func PublicGoogleAuthSetting(setting GoogleAuthSetting) map[string]interface{} {
|
||||
normalized := NormalizeGoogleAuthSetting(setting)
|
||||
return map[string]interface{}{
|
||||
"enabled": normalized.Enabled && normalized.ClientID != "",
|
||||
"client_id": normalized.ClientID,
|
||||
}
|
||||
}
|
||||
|
||||
// DecodeGoogleAuthSetting 从持久化 JSON 解码,并对缺失字段使用 fallback。
|
||||
func DecodeGoogleAuthSetting(raw jsonmap.JSON, fallback GoogleAuthSetting) GoogleAuthSetting {
|
||||
next := fallback
|
||||
|
||||
@@ -81,33 +81,10 @@ func NewUpdater() *Updater {
|
||||
}
|
||||
}
|
||||
|
||||
// Apply 下载指定发行版的当前平台归档并替换正在运行的二进制。
|
||||
// progress 可为 nil;非 nil 时会在各阶段回调,用于前端展示进度。
|
||||
//
|
||||
// 成功返回后二进制已就位,但进程仍是旧版本,需由调用方决定何时重启。
|
||||
func (u *Updater) Apply(ctx context.Context, release *version.Release, progress func(stage Stage, percent int)) error {
|
||||
execPath, err := ExecutablePath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 覆盖整个下载 + 替换过程,而不只是 swap 那一瞬:下载期间跑一次 CLI 回滚,
|
||||
// 会把 .backup 消耗掉,随后 swapBinary 又生成一个指向新版本的 .backup,
|
||||
// 结果是两边都以为自己成功了,可恢复的旧二进制却已经没了。
|
||||
unlock, err := acquireBinaryLock(execPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer unlock()
|
||||
|
||||
return u.applyLocked(ctx, release, execPath, progress)
|
||||
}
|
||||
|
||||
// applyLocked 执行实际升级,调用方必须已经持有 execPath 对应的跨进程锁。
|
||||
//
|
||||
// Manager.Start 在请求 GitHub release 之前取得锁并把所有权传到这里,从而覆盖
|
||||
// 「版本检查 → 下载 → 校验 → 替换 → 元数据落盘」完整事务;Apply 这个公开入口
|
||||
// 则在上面自行取得同一把锁后再调用。
|
||||
// 「版本检查 → 下载 → 校验 → 替换 → 元数据落盘」完整事务。
|
||||
func (u *Updater) applyLocked(ctx context.Context, release *version.Release, execPath string, progress func(stage Stage, percent int)) error {
|
||||
report := func(stage Stage, percent int) {
|
||||
if progress != nil {
|
||||
|
||||
Reference in new issue
Block a user