Skip to content
Snippets Groups Projects
Commit 46c7531b authored by Xavier Perret's avatar Xavier Perret
Browse files

starting to refactored the application

parent 0e13df10
No related branches found
No related tags found
1 merge request!2added file to separate client function from the server
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")
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment