mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package databag
|
|
|
|
import (
|
|
"errors"
|
|
"gorm.io/gorm"
|
|
"databag/internal/store"
|
|
)
|
|
|
|
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"
|
|
|
|
func getStrConfigValue(configID string, empty string) string {
|
|
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
|
|
}
|
|
|
|
func getNumConfigValue(configID string, empty int64) int64 {
|
|
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
|
|
}
|
|
|
|
func getBoolConfigValue(configID string, empty bool) bool {
|
|
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
|
|
}
|
|
|
|
func getBinConfigValue(configID string, empty []byte) []byte {
|
|
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
|
|
}
|