Refactored error declaration, removed unnecessary
return statements, and added error handling in PostConsumeTokenQuota function
This commit is contained in:
parent
bd582dbd2d
commit
bbe1104a00
@ -159,5 +159,4 @@ func DeleteHistoryLogs(c *gin.Context) {
|
|||||||
"message": "",
|
"message": "",
|
||||||
"data": count,
|
"data": count,
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,6 @@ func GetStatus(c *gin.Context) {
|
|||||||
"display_in_currency": common.DisplayInCurrencyEnabled,
|
"display_in_currency": common.DisplayInCurrencyEnabled,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetNotice(c *gin.Context) {
|
func GetNotice(c *gin.Context) {
|
||||||
@ -50,7 +49,6 @@ func GetNotice(c *gin.Context) {
|
|||||||
"message": "",
|
"message": "",
|
||||||
"data": common.OptionMap["Notice"],
|
"data": common.OptionMap["Notice"],
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAbout(c *gin.Context) {
|
func GetAbout(c *gin.Context) {
|
||||||
@ -61,7 +59,6 @@ func GetAbout(c *gin.Context) {
|
|||||||
"message": "",
|
"message": "",
|
||||||
"data": common.OptionMap["About"],
|
"data": common.OptionMap["About"],
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetHomePageContent(c *gin.Context) {
|
func GetHomePageContent(c *gin.Context) {
|
||||||
@ -72,7 +69,6 @@ func GetHomePageContent(c *gin.Context) {
|
|||||||
"message": "",
|
"message": "",
|
||||||
"data": common.OptionMap["HomePageContent"],
|
"data": common.OptionMap["HomePageContent"],
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendEmailVerification(c *gin.Context) {
|
func SendEmailVerification(c *gin.Context) {
|
||||||
@ -125,7 +121,6 @@ func SendEmailVerification(c *gin.Context) {
|
|||||||
"success": true,
|
"success": true,
|
||||||
"message": "",
|
"message": "",
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendPasswordResetEmail(c *gin.Context) {
|
func SendPasswordResetEmail(c *gin.Context) {
|
||||||
@ -164,7 +159,6 @@ func SendPasswordResetEmail(c *gin.Context) {
|
|||||||
"success": true,
|
"success": true,
|
||||||
"message": "",
|
"message": "",
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type PasswordResetRequest struct {
|
type PasswordResetRequest struct {
|
||||||
@ -212,5 +206,4 @@ func ResetPassword(c *gin.Context) {
|
|||||||
"message": "",
|
"message": "",
|
||||||
"data": password,
|
"data": password,
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,6 @@ func GetOptions(c *gin.Context) {
|
|||||||
"message": "",
|
"message": "",
|
||||||
"data": options,
|
"data": options,
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateOption(c *gin.Context) {
|
func UpdateOption(c *gin.Context) {
|
||||||
@ -103,5 +102,4 @@ func UpdateOption(c *gin.Context) {
|
|||||||
"success": true,
|
"success": true,
|
||||||
"message": "",
|
"message": "",
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"one-api/common"
|
"one-api/common"
|
||||||
"one-api/model"
|
"one-api/model"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetAllRedemptions(c *gin.Context) {
|
func GetAllRedemptions(c *gin.Context) {
|
||||||
@ -26,7 +27,6 @@ func GetAllRedemptions(c *gin.Context) {
|
|||||||
"message": "",
|
"message": "",
|
||||||
"data": redemptions,
|
"data": redemptions,
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func SearchRedemptions(c *gin.Context) {
|
func SearchRedemptions(c *gin.Context) {
|
||||||
@ -44,7 +44,6 @@ func SearchRedemptions(c *gin.Context) {
|
|||||||
"message": "",
|
"message": "",
|
||||||
"data": redemptions,
|
"data": redemptions,
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetRedemption(c *gin.Context) {
|
func GetRedemption(c *gin.Context) {
|
||||||
@ -69,7 +68,6 @@ func GetRedemption(c *gin.Context) {
|
|||||||
"message": "",
|
"message": "",
|
||||||
"data": redemption,
|
"data": redemption,
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddRedemption(c *gin.Context) {
|
func AddRedemption(c *gin.Context) {
|
||||||
@ -129,7 +127,6 @@ func AddRedemption(c *gin.Context) {
|
|||||||
"message": "",
|
"message": "",
|
||||||
"data": keys,
|
"data": keys,
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteRedemption(c *gin.Context) {
|
func DeleteRedemption(c *gin.Context) {
|
||||||
@ -146,7 +143,6 @@ func DeleteRedemption(c *gin.Context) {
|
|||||||
"success": true,
|
"success": true,
|
||||||
"message": "",
|
"message": "",
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateRedemption(c *gin.Context) {
|
func UpdateRedemption(c *gin.Context) {
|
||||||
@ -188,5 +184,4 @@ func UpdateRedemption(c *gin.Context) {
|
|||||||
"message": "",
|
"message": "",
|
||||||
"data": cleanRedemption,
|
"data": cleanRedemption,
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"one-api/common"
|
"one-api/common"
|
||||||
"one-api/model"
|
"one-api/model"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetAllTokens(c *gin.Context) {
|
func GetAllTokens(c *gin.Context) {
|
||||||
@ -27,7 +28,6 @@ func GetAllTokens(c *gin.Context) {
|
|||||||
"message": "",
|
"message": "",
|
||||||
"data": tokens,
|
"data": tokens,
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func SearchTokens(c *gin.Context) {
|
func SearchTokens(c *gin.Context) {
|
||||||
@ -46,7 +46,6 @@ func SearchTokens(c *gin.Context) {
|
|||||||
"message": "",
|
"message": "",
|
||||||
"data": tokens,
|
"data": tokens,
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetToken(c *gin.Context) {
|
func GetToken(c *gin.Context) {
|
||||||
@ -72,7 +71,6 @@ func GetToken(c *gin.Context) {
|
|||||||
"message": "",
|
"message": "",
|
||||||
"data": token,
|
"data": token,
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTokenStatus(c *gin.Context) {
|
func GetTokenStatus(c *gin.Context) {
|
||||||
@ -138,7 +136,6 @@ func AddToken(c *gin.Context) {
|
|||||||
"success": true,
|
"success": true,
|
||||||
"message": "",
|
"message": "",
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteToken(c *gin.Context) {
|
func DeleteToken(c *gin.Context) {
|
||||||
@ -156,7 +153,6 @@ func DeleteToken(c *gin.Context) {
|
|||||||
"success": true,
|
"success": true,
|
||||||
"message": "",
|
"message": "",
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateToken(c *gin.Context) {
|
func UpdateToken(c *gin.Context) {
|
||||||
@ -224,5 +220,4 @@ func UpdateToken(c *gin.Context) {
|
|||||||
"message": "",
|
"message": "",
|
||||||
"data": cleanToken,
|
"data": cleanToken,
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,6 @@ func Register(c *gin.Context) {
|
|||||||
"success": true,
|
"success": true,
|
||||||
"message": "",
|
"message": "",
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAllUsers(c *gin.Context) {
|
func GetAllUsers(c *gin.Context) {
|
||||||
@ -194,7 +193,6 @@ func GetAllUsers(c *gin.Context) {
|
|||||||
"message": "",
|
"message": "",
|
||||||
"data": users,
|
"data": users,
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func SearchUsers(c *gin.Context) {
|
func SearchUsers(c *gin.Context) {
|
||||||
@ -212,7 +210,6 @@ func SearchUsers(c *gin.Context) {
|
|||||||
"message": "",
|
"message": "",
|
||||||
"data": users,
|
"data": users,
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetUser(c *gin.Context) {
|
func GetUser(c *gin.Context) {
|
||||||
@ -245,7 +242,6 @@ func GetUser(c *gin.Context) {
|
|||||||
"message": "",
|
"message": "",
|
||||||
"data": user,
|
"data": user,
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateAccessToken(c *gin.Context) {
|
func GenerateAccessToken(c *gin.Context) {
|
||||||
@ -281,7 +277,6 @@ func GenerateAccessToken(c *gin.Context) {
|
|||||||
"message": "",
|
"message": "",
|
||||||
"data": user.AccessToken,
|
"data": user.AccessToken,
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAffCode(c *gin.Context) {
|
func GetAffCode(c *gin.Context) {
|
||||||
@ -309,7 +304,6 @@ func GetAffCode(c *gin.Context) {
|
|||||||
"message": "",
|
"message": "",
|
||||||
"data": user.AffCode,
|
"data": user.AffCode,
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSelf(c *gin.Context) {
|
func GetSelf(c *gin.Context) {
|
||||||
@ -327,7 +321,6 @@ func GetSelf(c *gin.Context) {
|
|||||||
"message": "",
|
"message": "",
|
||||||
"data": user,
|
"data": user,
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateUser(c *gin.Context) {
|
func UpdateUser(c *gin.Context) {
|
||||||
@ -391,7 +384,6 @@ func UpdateUser(c *gin.Context) {
|
|||||||
"success": true,
|
"success": true,
|
||||||
"message": "",
|
"message": "",
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateSelf(c *gin.Context) {
|
func UpdateSelf(c *gin.Context) {
|
||||||
@ -438,7 +430,6 @@ func UpdateSelf(c *gin.Context) {
|
|||||||
"success": true,
|
"success": true,
|
||||||
"message": "",
|
"message": "",
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteUser(c *gin.Context) {
|
func DeleteUser(c *gin.Context) {
|
||||||
@ -500,7 +491,6 @@ func DeleteSelf(c *gin.Context) {
|
|||||||
"success": true,
|
"success": true,
|
||||||
"message": "",
|
"message": "",
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateUser(c *gin.Context) {
|
func CreateUser(c *gin.Context) {
|
||||||
@ -549,7 +539,6 @@ func CreateUser(c *gin.Context) {
|
|||||||
"success": true,
|
"success": true,
|
||||||
"message": "",
|
"message": "",
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ManageRequest struct {
|
type ManageRequest struct {
|
||||||
@ -666,7 +655,6 @@ func ManageUser(c *gin.Context) {
|
|||||||
"message": "",
|
"message": "",
|
||||||
"data": clearUser,
|
"data": clearUser,
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func EmailBind(c *gin.Context) {
|
func EmailBind(c *gin.Context) {
|
||||||
@ -708,7 +696,6 @@ func EmailBind(c *gin.Context) {
|
|||||||
"success": true,
|
"success": true,
|
||||||
"message": "",
|
"message": "",
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type topUpRequest struct {
|
type topUpRequest struct {
|
||||||
@ -739,5 +726,4 @@ func TopUp(c *gin.Context) {
|
|||||||
"message": "",
|
"message": "",
|
||||||
"data": quota,
|
"data": quota,
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,13 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"one-api/common"
|
"one-api/common"
|
||||||
"one-api/model"
|
"one-api/model"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type wechatLoginResponse struct {
|
type wechatLoginResponse struct {
|
||||||
@ -160,5 +161,4 @@ func WeChatBind(c *gin.Context) {
|
|||||||
"success": true,
|
"success": true,
|
||||||
"message": "",
|
"message": "",
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ func GetRandomSatisfiedChannel(group string, model string, stream bool) (*Channe
|
|||||||
trueVal = "true"
|
trueVal = "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error = nil
|
var err error
|
||||||
|
|
||||||
cmdWhere := groupCol + " = ? and model = ? and enabled = " + trueVal
|
cmdWhere := groupCol + " = ? and model = ? and enabled = " + trueVal
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ func SearchChannels(keyword string) (channels []*Channel, err error) {
|
|||||||
|
|
||||||
func GetChannelById(id int, selectAll bool) (*Channel, error) {
|
func GetChannelById(id int, selectAll bool) (*Channel, error) {
|
||||||
channel := Channel{Id: id}
|
channel := Channel{Id: id}
|
||||||
var err error = nil
|
var err error
|
||||||
if selectAll {
|
if selectAll {
|
||||||
err = DB.First(&channel, "id = ?", id).Error
|
err = DB.First(&channel, "id = ?", id).Error
|
||||||
} else {
|
} else {
|
||||||
|
@ -218,6 +218,9 @@ func PreConsumeTokenQuota(tokenId int, quota int) (err error) {
|
|||||||
|
|
||||||
func PostConsumeTokenQuota(tokenId int, quota int) (err error) {
|
func PostConsumeTokenQuota(tokenId int, quota int) (err error) {
|
||||||
token, err := GetTokenById(tokenId)
|
token, err := GetTokenById(tokenId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if quota > 0 {
|
if quota > 0 {
|
||||||
err = DecreaseUserQuota(token.UserId, quota)
|
err = DecreaseUserQuota(token.UserId, quota)
|
||||||
} else {
|
} else {
|
||||||
|
@ -54,7 +54,7 @@ func GetUserById(id int, selectAll bool) (*User, error) {
|
|||||||
return nil, errors.New("id 为空!")
|
return nil, errors.New("id 为空!")
|
||||||
}
|
}
|
||||||
user := User{Id: id}
|
user := User{Id: id}
|
||||||
var err error = nil
|
var err error
|
||||||
if selectAll {
|
if selectAll {
|
||||||
err = DB.First(&user, "id = ?", id).Error
|
err = DB.First(&user, "id = ?", id).Error
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user