From 46c7531b58f743acce0baea97610e3c012f3bc0b Mon Sep 17 00:00:00 2001 From: Xavier Perret <xa.perret@outlook.com> Date: Fri, 28 Oct 2022 11:55:06 +0200 Subject: [PATCH] starting to refactored the application --- app/server.go | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 app/server.go diff --git a/app/server.go b/app/server.go new file mode 100644 index 0000000..ce238a1 --- /dev/null +++ b/app/server.go @@ -0,0 +1,59 @@ +package main + +import ( + "fmt" + "gopkg.in/yaml.v3" + . "node/types" + "node/utilities" + "os" +) + +/** + * @file Server.go - Server for the blockchain + * @brief Distributed Systems - Blockchain, each instance of this program is a node in the blockchain + * @author Xavier Perret + * @date 28/10/2022 + * @version 1.3 + */ + +func main() { + argsLen := len(os.Args) + isThereEnoughArgs := argsLen <= 1 + if isThereEnoughArgs { + fmt.Println("First argument should be the path of the config file '--path=<config.yaml>'") + os.Exit(1) + } + + // init configuration + args := os.Args[1:] + fmt.Println("Program started with arguments", args) + fmt.Println("config file path is ", args[0][7:]) + + buf, err := os.ReadFile(args[0][7:]) + if err != nil { + fmt.Println("Error while reading the config file", err) + fmt.Println("Exiting...") + os.Exit(1) + } + + var c Config + err = yaml.Unmarshal(buf, &c) + if err != nil { + os.Exit(1) + } + + utilities.PrintConfig(c) + + amIRoot := argsLen == 3 + if amIRoot { + if os.Args[3] == "--root" { + amIRoot = true + } + } + if !amIRoot { + fmt.Println("Third argument is not --root meaning this node is not meant to be directly stimulated by the client") + } + + fmt.Println("Launching server loop") + fmt.Println("Launching user input command line") +} -- GitLab