Add: GetIntSetting helper
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user