alist/internal/setting/setting.go

31 lines
506 B
Go
Raw Normal View History

2022-06-27 09:25:19 +00:00
package setting
import (
"strconv"
2022-08-03 06:26:59 +00:00
"github.com/alist-org/alist/v3/internal/db"
2022-06-27 09:25:19 +00:00
)
2022-09-06 06:39:21 +00:00
func GetStr(key string, defaultValue ...string) string {
val, ok := db.GetSettingsMap().Load(key)
2022-06-27 13:34:13 +00:00
if !ok {
if len(defaultValue) > 0 {
return defaultValue[0]
}
return ""
}
return val
2022-06-27 09:25:19 +00:00
}
2022-09-06 06:39:21 +00:00
func GetInt(key string, defaultVal int) int {
i, err := strconv.Atoi(GetStr(key))
2022-06-27 09:25:19 +00:00
if err != nil {
return defaultVal
}
return i
}
2022-09-06 06:39:21 +00:00
func GetBool(key string) bool {
return GetStr(key) == "true" || GetStr(key) == "1"
2022-06-27 09:25:19 +00:00
}