2024-01-20 01:27:10 +02:00
|
|
|
package config
|
|
|
|
|
2024-01-20 02:06:27 +02:00
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
2024-01-20 01:27:10 +02:00
|
|
|
type DHConfig struct {
|
2024-01-21 21:42:58 +02:00
|
|
|
CleanupServiceFrequency int `json:"cleanupServiceFrequency"`
|
|
|
|
DiskFetchFrequency int `json:"diskFetchFrequency"`
|
|
|
|
MaxHistoryAge int `json:"maxHistoryAge"`
|
|
|
|
|
|
|
|
DatabaseFilePath string `json:"databaseFilePath"`
|
|
|
|
|
|
|
|
Listen string `json:"listen"`
|
|
|
|
|
|
|
|
IdentityUsername string `json:"identityUsername"`
|
|
|
|
IdentityPassword string `json:"identityPassword"`
|
2024-01-21 22:56:53 +02:00
|
|
|
|
2024-01-22 01:49:13 +02:00
|
|
|
IsDocker bool `json:isDocker`
|
|
|
|
|
2024-01-21 22:56:53 +02:00
|
|
|
DebugMode bool `json:"debugMode"`
|
2024-01-20 01:27:10 +02:00
|
|
|
}
|
|
|
|
|
2024-01-22 00:28:07 +02:00
|
|
|
var config *DHConfig = nil
|
|
|
|
|
|
|
|
func GetConfiguration() *DHConfig {
|
|
|
|
|
|
|
|
if config != nil {
|
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
|
|
|
config = &DHConfig{
|
2024-01-21 21:42:58 +02:00
|
|
|
DiskFetchFrequency: 5,
|
2024-01-21 21:43:24 +02:00
|
|
|
CleanupServiceFrequency: 3600,
|
2024-01-21 21:42:58 +02:00
|
|
|
MaxHistoryAge: 2592000,
|
|
|
|
DatabaseFilePath: "./data.sqlite",
|
|
|
|
IdentityUsername: "admin",
|
|
|
|
IdentityPassword: "admin",
|
2024-01-20 02:09:10 +02:00
|
|
|
|
2024-01-22 01:49:13 +02:00
|
|
|
IsDocker: false,
|
|
|
|
|
2024-01-20 02:09:10 +02:00
|
|
|
Listen: ":8080",
|
2024-01-20 02:06:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if val, exists := os.LookupEnv("DISK_FETCH_FREQUENCY"); exists {
|
|
|
|
if intValue, err := strconv.Atoi(val); err == nil {
|
|
|
|
config.DiskFetchFrequency = intValue
|
|
|
|
}
|
|
|
|
}
|
2024-01-20 01:27:10 +02:00
|
|
|
|
2024-01-21 21:42:58 +02:00
|
|
|
if val, exists := os.LookupEnv("CLEANUP_SERVICE_FREQUENCY"); exists {
|
|
|
|
if intValue, err := strconv.Atoi(val); err == nil {
|
|
|
|
config.CleanupServiceFrequency = intValue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-20 02:06:27 +02:00
|
|
|
if val, exists := os.LookupEnv("MAX_HISTORY_AGE"); exists {
|
|
|
|
if intValue, err := strconv.Atoi(val); err == nil {
|
|
|
|
config.MaxHistoryAge = intValue
|
|
|
|
}
|
2024-01-20 01:27:10 +02:00
|
|
|
}
|
|
|
|
|
2024-01-20 02:09:10 +02:00
|
|
|
if val, exists := os.LookupEnv("LISTEN"); exists {
|
|
|
|
config.Listen = val
|
|
|
|
}
|
|
|
|
|
2024-01-20 18:35:50 +02:00
|
|
|
if val, exists := os.LookupEnv("DATABASE_FILE_PATH"); exists {
|
|
|
|
config.DatabaseFilePath = val
|
|
|
|
}
|
|
|
|
|
2024-01-21 18:40:40 +02:00
|
|
|
if val, exists := os.LookupEnv("IDENTITY_USERNAME"); exists {
|
|
|
|
config.IdentityUsername = val
|
|
|
|
}
|
|
|
|
|
|
|
|
if val, exists := os.LookupEnv("IDENTITY_PASSWORD"); exists {
|
|
|
|
config.IdentityPassword = val
|
|
|
|
}
|
|
|
|
|
2024-01-21 22:56:53 +02:00
|
|
|
if val, exists := os.LookupEnv("DEBUG_MODE"); exists {
|
|
|
|
if isDebug, err := strconv.ParseBool(val); err == nil {
|
|
|
|
config.DebugMode = isDebug
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-22 01:49:13 +02:00
|
|
|
if val, exists := os.LookupEnv("IS_DOCKER"); exists {
|
|
|
|
if isDocker, err := strconv.ParseBool(val); err == nil {
|
|
|
|
config.IsDocker = isDocker
|
|
|
|
|
|
|
|
config.DatabaseFilePath = "/data/data.sqlite"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-20 02:06:27 +02:00
|
|
|
return config
|
2024-01-20 01:27:10 +02:00
|
|
|
}
|