-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (48 loc) · 1.24 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"VNFS/internal/node"
"encoding/json"
"flag"
"fmt"
"os"
)
func main() {
// Parse command-line arguments for the config file path.
configFilePath := flag.String("config", "configs/config.json", "Path to the node config file")
flag.Parse()
// Load the node configuration.
NodeConfig := loadConfig(*configFilePath)
nodeInstance, err := node.NewNode(NodeConfig)
if err != nil {
fmt.Printf("Error creating node: %v\n", err)
os.Exit(1)
}
// Letssssss Start the node :)
fmt.Printf("Starting Node %d at address %s...\n", NodeConfig.NodeId, NodeConfig.Address)
err = nodeInstance.Start()
if err != nil {
fmt.Printf("Error starting node: %v\n", err)
os.Exit(1)
}
// Graceful shutdown :)
defer func() {
fmt.Println("Shutting down node...")
nodeInstance.Shutdown()
}()
}
// Helper function to load config file
func loadConfig(configFile string) *node.NodeConfig {
file, err := os.Open(configFile)
if err != nil {
fmt.Printf("Failed to open config file: %v\n", err)
os.Exit(1)
}
defer file.Close()
decoder := json.NewDecoder(file)
nodeConfig := &node.NodeConfig{}
if err := decoder.Decode(nodeConfig); err != nil {
fmt.Printf("Error decoding config file: %v\n", err)
os.Exit(1)
}
return nodeConfig
}