mirror of
https://github.com/songquanpeng/message-pusher.git
synced 2025-09-27 04:26:31 +08:00
perf: replace multiple if statements with switch
This commit is contained in:
@@ -40,24 +40,31 @@ func UpdateOption(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if option.Key == "GitHubOAuthEnabled" && option.Value == "true" && common.GitHubClientId == "" {
|
switch option.Key {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
case "GitHubOAuthEnabled":
|
||||||
"success": false,
|
if option.Value == "true" && common.GitHubClientId == "" {
|
||||||
"message": "无法启用 GitHub OAuth,请先填入 GitHub Client ID 以及 GitHub Client Secret!",
|
c.JSON(http.StatusOK, gin.H{
|
||||||
})
|
"success": false,
|
||||||
return
|
"message": "无法启用 GitHub OAuth,请先填入 GitHub Client ID 以及 GitHub Client Secret!",
|
||||||
} else if option.Key == "WeChatAuthEnabled" && option.Value == "true" && common.WeChatServerAddress == "" {
|
})
|
||||||
c.JSON(http.StatusOK, gin.H{
|
return
|
||||||
"success": false,
|
}
|
||||||
"message": "无法启用微信登录,请先填入微信登录相关配置信息!",
|
case "WeChatAuthEnabled":
|
||||||
})
|
if option.Value == "true" && common.WeChatServerAddress == "" {
|
||||||
return
|
c.JSON(http.StatusOK, gin.H{
|
||||||
} else if option.Key == "TurnstileCheckEnabled" && option.Value == "true" && common.TurnstileSiteKey == "" {
|
"success": false,
|
||||||
c.JSON(http.StatusOK, gin.H{
|
"message": "无法启用微信登录,请先填入微信登录相关配置信息!",
|
||||||
"success": false,
|
})
|
||||||
"message": "无法启用 Turnstile 校验,请先填入 Turnstile 校验相关配置信息!",
|
return
|
||||||
})
|
}
|
||||||
return
|
case "TurnstileCheckEnabled":
|
||||||
|
if option.Value == "true" && common.TurnstileSiteKey == "" {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "无法启用 Turnstile 校验,请先填入 Turnstile 校验相关配置信息!",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
err = model.UpdateOption(option.Key, option.Value)
|
err = model.UpdateOption(option.Key, option.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"message-pusher/common"
|
"message-pusher/common"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -55,10 +54,6 @@ func InitOptionMap() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func UpdateOption(key string, value string) error {
|
func UpdateOption(key string, value string) error {
|
||||||
if key == "StatEnabled" && value == "true" && !common.RedisEnabled {
|
|
||||||
return errors.New("未启用 Redis,无法启用统计功能")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save to database first
|
// Save to database first
|
||||||
option := Option{
|
option := Option{
|
||||||
Key: key,
|
Key: key,
|
||||||
|
Reference in New Issue
Block a user