Commit 51d610c

Richard Luby <richluby@gmail.com>
2016-10-06 10:03:59
added exit codes
program now provides unified exit code statuses for specific error types
1 parent 47566e6
Changed files (1)
questioner.go
@@ -6,8 +6,22 @@ import (
 	"fmt"
 	"github.com/BurntSushi/toml"
 	"io/ioutil"
+	"os"
 )
 
+// define exit error codes
+type EXIT_CODES struct {
+	BAD_CONFIG,
+	FILE_IO_ERROR,
+	NETWORK_IO_ERROR int
+}
+
+// declare exit codes
+var EXIT_CODE = EXIT_CODES{
+	BAD_CONFIG:       1,
+	FILE_IO_ERROR:    2,
+	NETWORK_IO_ERROR: 3}
+
 // define defaults for the server
 type CONFIG struct {
 	LISTEN_PORT, MAX_CONNECTIONS int
@@ -32,12 +46,14 @@ func LoadConfiguration(cfgFile string) CONFIG {
 	} else {
 		buffer, err := ioutil.ReadFile(cfgFile)
 		if err != nil {
-			panic(fmt.Sprintf("%+v", err))
+			fmt.Printf("%+v\n", err.Error())
+			os.Exit(EXIT_CODE.FILE_IO_ERROR)
 		}
 		contents = string(buffer)
 	}
 	if _, err := toml.Decode(contents, &config); err != nil {
-		panic(fmt.Sprintf("%+v", err))
+		fmt.Printf("%+v\n", err.Error())
+		os.Exit(EXIT_CODE.BAD_CONFIG)
 	}
 	return config
 }