Set up nested directory structure for interfaces, configuration, structs, libraries

This commit is contained in:
Michael Hohn
2024-05-10 13:28:47 -07:00
committed by =Michael Hohn
parent 12595077c7
commit d38b561309
2 changed files with 34 additions and 27 deletions

View File

@@ -9,7 +9,6 @@ import (
"log/slog"
"os"
"github.com/BurntSushi/toml"
"github.com/advanced-security/mrvacommander/config/mcc"
"github.com/advanced-security/mrvacommander/interfaces/mci"
"github.com/advanced-security/mrvacommander/lib/commander/lcmem"
@@ -58,7 +57,7 @@ func main() {
}
// Read configuration
config := loadConfig("cconfig.toml")
config := mcc.LoadConfig("cconfig.toml")
// Apply 'mode' flag
switch *mode {
@@ -89,28 +88,3 @@ func main() {
// Run in the chosen mode
}
type MCConfig struct {
commander mcc.Commander
logger mcc.Logger
queue mcc.Queue
storage mcc.Storage
runner mcc.Runner
}
func loadConfig(fname string) *MCConfig {
if _, err := os.Stat(fname); err != nil {
slog.Error("Configuration file %s not found", f)
os.Exit(1)
}
var config MCConfig
_, err := toml.DecodeFile(fname, &config)
if err != nil {
slog.Error("", err)
os.Exit(1)
}
return &config
}

33
config/mcc/system.go Normal file
View File

@@ -0,0 +1,33 @@
package mcc
import (
"log/slog"
"os"
"github.com/BurntSushi/toml"
)
type System struct {
commander Commander
logger Logger
queue Queue
storage Storage
runner Runner
}
func LoadConfig(fname string) *System {
if _, err := os.Stat(fname); err != nil {
slog.Error("Configuration file %s not found", fname)
os.Exit(1)
}
var config System
_, err := toml.DecodeFile(fname, &config)
if err != nil {
slog.Error("", err)
os.Exit(1)
}
return &config
}