2022-01-12 21:12:40 +00:00
|
|
|
package databag
|
|
|
|
|
|
|
|
import (
|
2022-07-22 19:28:14 +00:00
|
|
|
"databag/internal/store"
|
|
|
|
"errors"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
2022-01-12 21:12:40 +00:00
|
|
|
|
2022-07-22 18:01:29 +00:00
|
|
|
const CNFOpenAccess = "open_access"
|
|
|
|
const CNFAccountLimit = "account_limit"
|
|
|
|
const CNFConfigured = "configured"
|
|
|
|
const CNFToken = "token"
|
|
|
|
const CNFDomain = "domain"
|
|
|
|
const CNFStorage = "storage"
|
|
|
|
const CNFAssetPath = "asset_path"
|
|
|
|
const CNFScriptPath = "script_path"
|
2022-01-17 05:55:25 +00:00
|
|
|
|
2022-07-22 17:15:44 +00:00
|
|
|
func getStrConfigValue(configID string, empty string) string {
|
2022-07-22 19:28:14 +00:00
|
|
|
var config store.Config
|
|
|
|
err := store.DB.Where("config_id = ?", configID).First(&config).Error
|
|
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
|
return empty
|
|
|
|
}
|
|
|
|
return config.StrValue
|
2022-01-12 21:12:40 +00:00
|
|
|
}
|
|
|
|
|
2022-07-22 17:15:44 +00:00
|
|
|
func getNumConfigValue(configID string, empty int64) int64 {
|
2022-07-22 19:28:14 +00:00
|
|
|
var config store.Config
|
|
|
|
err := store.DB.Where("config_id = ?", configID).First(&config).Error
|
|
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
|
return empty
|
|
|
|
}
|
|
|
|
return config.NumValue
|
2022-01-12 21:12:40 +00:00
|
|
|
}
|
|
|
|
|
2022-07-22 17:15:44 +00:00
|
|
|
func getBoolConfigValue(configID string, empty bool) bool {
|
2022-07-22 19:28:14 +00:00
|
|
|
var config store.Config
|
|
|
|
err := store.DB.Where("config_id = ?", configID).First(&config).Error
|
|
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
|
return empty
|
|
|
|
}
|
|
|
|
return config.BoolValue
|
2022-01-12 21:12:40 +00:00
|
|
|
}
|
|
|
|
|
2022-07-22 17:15:44 +00:00
|
|
|
func getBinConfigValue(configID string, empty []byte) []byte {
|
2022-07-22 19:28:14 +00:00
|
|
|
var config store.Config
|
|
|
|
err := store.DB.Where("config_id = ?", configID).First(&config).Error
|
|
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
|
return empty
|
|
|
|
}
|
|
|
|
return config.BinValue
|
2022-01-12 21:12:40 +00:00
|
|
|
}
|