ce3babcc33
Closes HIF-3 Stage 1 完整闭环 PR C:用户 API + 后台 CRUD + 抽奖事务服务 + 审计 + QA curl。合并后 Stage 1 可交测试。 架构师 review R1(rulecaps depth≤8/nodes≤64/bytes≤8KB)+ R2(InviteHook source_ref 加 order: 前缀)已全部落地。 - 迁移 02158_admin_action_log:后台写操作审计 - xerr 100xxx 段:抽奖错误码(NotEligible/NoChances/ActivityEnded/RateLimited/NotClaimable/InternalError/RuleTooDeep/RuleTooMany/RuleTooLarge) - feature flag config.Lottery.Enable 默认 false,合并后线上零副作用 - draw service:feature flag → rate limit → pre-tx reads → nonce dedupe → Consume → Pick → 乐观扣库存 → 双快照 → Dispatch → finalize - 用户 API 4 个:GET /config、POST /draw、GET /records、POST /claim(Stage 1 返回 100010) - 后台 CRUD:活动 / 奖品 / rules PUT(rulecaps gate)/ chances/grant - audit.WriteAdminAction:与调用方 tx 同生共死,SHA1 body 摘要 - QA 脚本:qa/lottery/stage1_curl.sh 全链路 curl 测试覆盖:model 76.5% / draw 69% / handler 68.3% / hook 91.9% / rulecaps 87.8% / audit 100% 100 并发抢库存 + 10000 次概率分布 e2e 推 QA 环境(sqlmock 无法忠实模拟 InnoDB 行锁) CI 全绿:构建/Vet/测试 + golangci-lint
148 lines
5.9 KiB
Go
148 lines
5.9 KiB
Go
package xerr
|
|
|
|
var message map[uint32]string
|
|
|
|
func init() {
|
|
message = make(map[uint32]string)
|
|
message = map[uint32]string{
|
|
// General error
|
|
SUCCESS: "Success",
|
|
ERROR: "Internal Server Error",
|
|
// parameter error
|
|
TooManyRequests: "Too Many Requests",
|
|
InvalidParams: "Param Error",
|
|
ErrorTokenEmpty: "User token is empty",
|
|
ErrorTokenInvalid: "User token is invalid",
|
|
ErrorTokenExpire: "User token is expired",
|
|
SecretIsEmpty: "Secret is empty",
|
|
InvalidAccess: "Invalid access",
|
|
InvalidCiphertext: "Invalid ciphertext",
|
|
SignatureMissing: "Signature headers are missing",
|
|
SignatureExpired: "Signature is expired",
|
|
SignatureInvalid: "Signature is invalid",
|
|
SignatureReplay: "Signature nonce replay detected",
|
|
// Database error
|
|
DatabaseQueryError: "Database query error",
|
|
DatabaseUpdateError: "Database update error",
|
|
DatabaseInsertError: "Database insert error",
|
|
DatabaseDeletedError: "Database deleted error",
|
|
|
|
// User error
|
|
UserExist: "User already exists",
|
|
UserNotExist: "User does not exist",
|
|
UserPasswordError: "User password error",
|
|
UserDisabled: "User disabled",
|
|
InsufficientBalance: "Insufficient balance",
|
|
StopRegister: "Stop register",
|
|
TelegramNotBound: "Telegram not bound ",
|
|
UserNotBindOauth: "User not bind oauth method",
|
|
InviteCodeError: "Invite code error",
|
|
UserCommissionNotEnough: "佣金余额不足",
|
|
RegisterIPLimit: "Too many registrations",
|
|
EmailBindError: "Email already bound",
|
|
UserBindInviteCodeExist: "Invite code already bound",
|
|
FamilyMemberLimitExceeded: "家庭成员数量已达上限",
|
|
FamilyAlreadyBound: "已绑定家庭组",
|
|
FamilyCrossBindForbidden: "禁止跨家庭组绑定",
|
|
FamilyNotExist: "家庭组不存在",
|
|
FamilyStatusInvalid: "家庭组状态无效",
|
|
FamilyOwnerOperationForbidden: "家庭组所有者不允许此操作",
|
|
WithdrawalStatusInvalid: "提现状态无效",
|
|
|
|
// Node error
|
|
NodeExist: "Node already exists",
|
|
NodeNotExist: "Node does not exist",
|
|
NodeGroupExist: "Node group already exists",
|
|
NodeGroupNotExist: "Node group does not exist",
|
|
NodeGroupNotEmpty: "Node group is not empty",
|
|
|
|
//coupon error
|
|
CouponNotExist: "Coupon does not exist",
|
|
CouponAlreadyUsed: "Coupon has already been used",
|
|
CouponNotApplicable: "Coupon does not match the order or conditions",
|
|
CouponInsufficientUsage: "Coupon has insufficient remaining uses",
|
|
CouponExpired: "Coupon is expired",
|
|
|
|
// Subscribe
|
|
SubscribeExpired: "Subscribe is expired",
|
|
SubscribeNotAvailable: "Subscribe is not available",
|
|
UserSubscribeExist: "User has subscription",
|
|
SubscribeIsUsedError: "Subscribe is used",
|
|
SingleSubscribeModeExceedsLimit: "Single subscribe mode exceeds limit",
|
|
SubscribeQuotaLimit: "Subscribe quota limit",
|
|
SubscribeOutOfStock: "Subscribe out of stock",
|
|
SingleSubscribePlanMismatch: "Single subscribe mode does not support switching subscription by purchase",
|
|
SubscribeNewUserOnly: "This plan is only available for new users within 24 hours of registration",
|
|
|
|
// auth error
|
|
VerifyCodeError: "Verify code error",
|
|
|
|
// EnqueueError
|
|
QueueEnqueueError: " Queue enqueue error",
|
|
|
|
// System error
|
|
DebugModeError: "Debug mode is enabled",
|
|
|
|
SendSmsError: "短信发送失败",
|
|
|
|
GetAuthenticatorError: "Unsupported login method",
|
|
AuthenticatorNotSupportedError: "The authenticator does not support this method",
|
|
|
|
TelephoneAreaCodeIsEmpty: "Telephone area code is empty",
|
|
TodaySendCountExceedsLimit: "This account has reached the limit of sending times today",
|
|
SmsNotEnabled: "Telephone login is not enabled",
|
|
EmailNotEnabled: "Email function is not enabled yet",
|
|
PasswordOrVerificationCodeRequired: "Password or verification code required",
|
|
EmailExist: "Email already exists",
|
|
TelephoneExist: "Telephone already exists",
|
|
DeviceExist: "device exists",
|
|
PasswordIsEmpty: "password is empty",
|
|
AreaCodeIsEmpty: "国家区号不能为空",
|
|
TelephoneError: "telephone number error",
|
|
DeviceNotExist: "Device does not exist",
|
|
UseridNotMatch: "Userid not match",
|
|
DeviceBindLimitExceeded: "设备绑定数量已达上限",
|
|
|
|
// Order error
|
|
OrderNotExist: "Order does not exist",
|
|
PaymentMethodNotFound: "Payment method not found",
|
|
OrderStatusError: "Order status error",
|
|
InsufficientOfPeriod: "Insufficient number of period",
|
|
ExistAvailableTraffic: "存在可用流量",
|
|
OrderAlreadyRefunded: "Order already refunded",
|
|
OrderRefundNoSubscription: "Refund target subscription not found",
|
|
OrderRefundCommissionMismatch: "Refund commission source not found",
|
|
|
|
// Lottery error
|
|
LotteryNotEligible: "抽奖门槛未达成",
|
|
LotteryNoChances: "抽奖次数不足",
|
|
LotteryActivityEnded: "抽奖活动未开放",
|
|
LotteryRateLimited: "抽奖操作过于频繁,请稍后再试",
|
|
LotteryNotClaimable: "该奖品当前不支持领取",
|
|
LotteryInternalError: "抽奖服务暂时不可用",
|
|
LotteryRuleTooDeep: "规则树嵌套层数超限",
|
|
LotteryRuleTooMany: "规则树节点数超限",
|
|
LotteryRuleTooLarge: "规则树 JSON 体积超限",
|
|
|
|
// Permission error
|
|
PermissionDenied: "Permission denied",
|
|
}
|
|
|
|
}
|
|
|
|
func MapErrMsg(errCode uint32) string {
|
|
if msg, ok := message[errCode]; ok {
|
|
return msg
|
|
} else {
|
|
return "Internal Server Error"
|
|
}
|
|
}
|
|
|
|
func IsCodeErr(errCode uint32) bool {
|
|
if _, ok := message[errCode]; ok {
|
|
return true
|
|
} else {
|
|
return false
|
|
}
|
|
}
|