Add: GetIntSetting helper

This commit is contained in:
HFO4
2020-01-02 12:44:53 +08:00
parent fffcf1aa1b
commit a75be3a927
11 changed files with 59 additions and 110 deletions

View File

@@ -4,6 +4,7 @@ import (
"github.com/HFO4/cloudreve/pkg/cache"
"github.com/jinzhu/gorm"
"net/url"
"strconv"
)
// Setting 系统设置模型
@@ -72,3 +73,13 @@ func GetSiteURL() *url.URL {
}
return base
}
// GetIntSetting 获取整形设置值如果转换失败则返回默认值defaultVal
// TODO 测试
func GetIntSetting(key string, defaultVal int) int {
res, err := strconv.Atoi(GetSettingByName(key))
if err != nil {
return defaultVal
}
return res
}