From 12b9bd985879ab97cab57be4f39791a73fed6980 Mon Sep 17 00:00:00 2001 From: Michael Hohn Date: Fri, 10 May 2024 10:07:50 -0700 Subject: [PATCH] wip --- cmd/commander/cconfig.toml | 5 +++ cmd/commander/main.go | 44 +++++++++++++++++++ go.mod | 1 + go.sum | 2 + .../commander/lcmem/handlers.go | 0 5 files changed, 52 insertions(+) create mode 100644 cmd/commander/cconfig.toml rename cmd/commander/ccmem/main.go => lib/commander/lcmem/handlers.go (100%) diff --git a/cmd/commander/cconfig.toml b/cmd/commander/cconfig.toml new file mode 100644 index 0000000..543c318 --- /dev/null +++ b/cmd/commander/cconfig.toml @@ -0,0 +1,5 @@ +[commander] +[logger] +[queue] +[storage] +[runner] diff --git a/cmd/commander/main.go b/cmd/commander/main.go index e7d389f..2ec8d45 100644 --- a/cmd/commander/main.go +++ b/cmd/commander/main.go @@ -8,6 +8,8 @@ import ( "log" "log/slog" "os" + + "github.com/BurntSushi/toml" ) func main() { @@ -48,11 +50,17 @@ func main() { os.Exit(1) } + // Read configuration + config := loadConfig("cconfig.toml") + // Apply 'mode' flag switch *mode { case "standalone": + // Assemble ccmem case "container": + // Assemble cccontainer case "cluster": + // Assemble cccluster default: slog.Error("Invalid value for --mode. Allowed values are: standalone, container, cluster\n") os.Exit(1) @@ -62,4 +70,40 @@ func main() { log.Printf("Help: %t\n", *helpFlag) log.Printf("Log Level: %s\n", *logLevel) log.Printf("Mode: %s\n", *mode) + + // Run in the chosen mode + +} + +type CommanderParts struct { + commander MCCommander + logger MCLogger + queue MCQueue + storage MCStorage + runner MCRunner +} + +type MCConfig struct { + commander MCCConf + logger MCLConf + queue MCQConf + storage MCSConf + runner MCRConf +} + +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 } diff --git a/go.mod b/go.mod index dab9d9c..6ad6c1b 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( ) require ( + github.com/BurntSushi/toml v1.3.2 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect ) diff --git a/go.sum b/go.sum index 2bc6b7b..058b091 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= +github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= diff --git a/cmd/commander/ccmem/main.go b/lib/commander/lcmem/handlers.go similarity index 100% rename from cmd/commander/ccmem/main.go rename to lib/commander/lcmem/handlers.go