return0,types.NewErrorWithStatusCode(fmt.Errorf("pre-consume quota failed, user quota: %s, need quota: %s",logger.FormatQuota(userQuota),logger.FormatQuota(preConsumedQuota)),types.ErrorCodeInsufficientUserQuota,http.StatusForbidden,types.ErrOptionWithSkipRetry(),types.ErrOptionWithNoRecordErrorLog())
return0,types.NewErrorWithStatusCode(fmt.Errorf("pre-consume quota failed, user quota: %s, need quota: %s",logger.FormatQuota(userQuota),logger.FormatQuota(preConsumedQuota)),types.ErrorCodeInsufficientUserQuota,http.StatusForbidden,types.ErrOptionWithSkipRetry(),types.ErrOptionWithNoRecordErrorLog())
}
}
trustQuota:=common.GetTrustQuota()
relayInfo.UserQuota=userQuota
relayInfo.UserQuota=userQuota
ifuserQuota>100*preConsumedQuota{
ifuserQuota>trustQuota{
// 用户额度充足,判断令牌额度是否充足
// 用户额度充足,判断令牌额度是否充足
if!relayInfo.TokenUnlimited{
if!relayInfo.TokenUnlimited{
// 非无限令牌,判断令牌额度是否充足
// 非无限令牌,判断令牌额度是否充足
tokenQuota:=c.GetInt("token_quota")
tokenQuota:=c.GetInt("token_quota")
iftokenQuota>100*preConsumedQuota{
iftokenQuota>trustQuota{
// 令牌额度充足,信任令牌
// 令牌额度充足,信任令牌
preConsumedQuota=0
preConsumedQuota=0
logger.LogInfo(c,fmt.Sprintf("user %d quota %s and token %d quota %d are enough, trusted and no need to pre-consume",relayInfo.UserId,logger.FormatQuota(userQuota),relayInfo.TokenId,tokenQuota))
logger.LogInfo(c,fmt.Sprintf("user %d quota %s and token %d quota %d are enough, trusted and no need to pre-consume",relayInfo.UserId,logger.FormatQuota(userQuota),relayInfo.TokenId,tokenQuota))