2022-01-12 21:12:40 +00:00
|
|
|
package databag
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
"databag/internal/store"
|
|
|
|
)
|
|
|
|
|
2022-03-11 05:26:17 +00:00
|
|
|
const CONFIG_OPENACCESS = "open_access"
|
|
|
|
const CONFIG_ACCOUNTLIMIT = "account_limit"
|
2022-01-17 05:55:25 +00:00
|
|
|
const CONFIG_CONFIGURED = "configured"
|
|
|
|
const CONFIG_USERNAME = "username"
|
|
|
|
const CONFIG_PASSWORD = "password"
|
|
|
|
const CONFIG_DOMAIN = "domain"
|
|
|
|
const CONFIG_STORAGE = "storage"
|
2022-02-28 22:59:29 +00:00
|
|
|
const CONFIG_ASSETPATH = "asset_path"
|
2022-03-01 08:28:36 +00:00
|
|
|
const CONFIG_SCRIPTPATH = "script_path"
|
2022-01-17 05:55:25 +00:00
|
|
|
|
2022-01-12 21:12:40 +00:00
|
|
|
func getStrConfigValue(configId string, empty string) string {
|
|
|
|
var config store.Config
|
2022-01-15 04:45:53 +00:00
|
|
|
err := store.DB.Where("config_id = ?", configId).First(&config).Error
|
2022-01-12 21:12:40 +00:00
|
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
|
return empty
|
|
|
|
}
|
|
|
|
return config.StrValue
|
|
|
|
}
|
|
|
|
|
|
|
|
func getNumConfigValue(configId string, empty int64) int64 {
|
|
|
|
var config store.Config
|
2022-01-15 04:45:53 +00:00
|
|
|
err := store.DB.Where("config_id = ?", configId).First(&config).Error
|
2022-01-12 21:12:40 +00:00
|
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
|
return empty
|
|
|
|
}
|
|
|
|
return config.NumValue
|
|
|
|
}
|
|
|
|
|
|
|
|
func getBoolConfigValue(configId string, empty bool) bool {
|
|
|
|
var config store.Config
|
2022-01-15 04:45:53 +00:00
|
|
|
err := store.DB.Where("config_id = ?", configId).First(&config).Error
|
2022-01-12 21:12:40 +00:00
|
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
|
return empty
|
|
|
|
}
|
|
|
|
return config.BoolValue
|
|
|
|
}
|
|
|
|
|
|
|
|
func getBinConfigValue(configId string, empty []byte) []byte {
|
|
|
|
var config store.Config
|
2022-01-15 04:45:53 +00:00
|
|
|
err := store.DB.Where("config_id = ?", configId).First(&config).Error
|
2022-01-12 21:12:40 +00:00
|
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
|
return empty
|
|
|
|
}
|
|
|
|
return config.BinValue
|
|
|
|
}
|