From 013a69fa63c1c8ef0d23a1104b38fe71873d9970 Mon Sep 17 00:00:00 2001
From: Marc Di Luzio <marc.diluzio@gmail.com>
Date: Wed, 3 Jun 2020 17:29:56 +0100
Subject: [PATCH] Clean up main a little

---
 main.go | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/main.go b/main.go
index 898b4dd..b64a919 100644
--- a/main.go
+++ b/main.go
@@ -19,19 +19,23 @@ var data = flag.String("data", os.TempDir(), "Directory to store persistant data
 func main() {
 	flag.Parse()
 
+	// Print the version if requested
 	if *ver {
 		fmt.Println(version.Version)
 		os.Exit(0)
 	}
 
+	fmt.Printf("Initialising version %s...\n", version.Version)
+
 	// Set the persistence path
 	persistence.SetPath(*data)
 
+	// Create the server data
 	s := server.NewServer(
 		server.OptionPort(*port),
 		server.OptionPersistentData())
 
-	fmt.Printf("Initialising version %s...\n", version.Version)
+	// Initialise the server
 	if err := s.Initialise(); err != nil {
 		panic(err)
 	}
@@ -42,14 +46,18 @@ func main() {
 	go func() {
 		<-c
 		fmt.Println("SIGTERM recieved, exiting...")
-		s.Close()
+		if err := s.Close(); err != nil {
+			panic(err)
+		}
 		os.Exit(0)
 	}()
 
-	fmt.Println("Initialised")
+	fmt.Println("Running...")
 
+	// Run the server
 	s.Run()
 
+	// Close the server
 	if err := s.Close(); err != nil {
 		panic(err)
 	}