refactor: configs dir

This commit is contained in:
Anton
2023-12-04 23:57:03 +05:00
parent ad79565a93
commit 07b523cd4d
9 changed files with 19 additions and 17 deletions

View File

@@ -3,21 +3,28 @@ package config
import (
"encoding/json"
"os"
"path/filepath"
)
const (
configFilename = "config.json"
boxesFilename = "boxes.json"
commandsFilename = "commands.json"
)
// Read reads application config from JSON files.
func Read(cfgPath, boxPath, cmdPath string) (*Config, error) {
cfg, err := ReadConfig(cfgPath)
func Read(path string) (*Config, error) {
cfg, err := ReadConfig(filepath.Join(path, configFilename))
if err != nil {
return nil, err
}
cfg, err = ReadBoxes(cfg, boxPath)
cfg, err = ReadBoxes(cfg, filepath.Join(path, boxesFilename))
if err != nil {
return nil, err
}
cfg, err = ReadCommands(cfg, cmdPath)
cfg, err = ReadCommands(cfg, filepath.Join(path, commandsFilename))
if err != nil {
return nil, err
}