This repository has been archived on 2026-03-18. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
scabiosa/Tools/Config.go
2021-12-16 18:34:35 +01:00

56 lines
No EOL
1.2 KiB
Go

package Tools
import (
"encoding/json"
"os"
"scabiosa/Logging"
)
type Config struct {
LocalBackupPath string `json:"localBackupPath"`
SQLConfig struct{
EnableSQL bool `json:"enableSQL"`
SqlType string `json:"sqlType"`
SqlAddress string `json:"sql-address"`
SqlPort uint16 `json:"sql-port"`
Database string `json:"database"`
DbUser string `json:"db-user"`
DbPassword string `json:"db-password"`
} `json:"sqlConfig"`
FolderToBackup []struct{
BackupName string `json:"backupName"`
FolderPath string `json:"folderPath"`
StorageType string `json:"storageType"`
TargetPath string `json:"targetPath"`
CreateLocalBackup bool `json:"createLocalBackup"`
} `json:"foldersToBackup"`
}
type Backup struct{
backupName string
folderPath string
storageType string
createLocalBackup bool
}
func readConfig() []byte {
logger := Logging.DetailedLogger("ConfigHandler", "readConfig")
file, err := os.ReadFile("config/config.json")
if err != nil {
logger.Fatal(err)
}
return file
}
func GetConfig() Config {
logger := Logging.DetailedLogger("ConfigHandler", "GetConfig()")
var config Config
err := json.Unmarshal(readConfig(), &config)
if err != nil {
logger.Fatal(err)
}
return config
}