Commit a51d56c

Richard Luby <richluby@gmail.com>
2016-11-15 07:30:14
removed extra case checks
simplified logic for creating the server URL. client uses HTTPS setting in config.
1 parent b654fb2
Changed files (1)
client.go
@@ -26,21 +26,21 @@ type CLIENT_CONFIG struct {
 }
 
 var clientConfig CLIENT_CONFIG
+var client http.Client
 
 // loadClientConfiguration loads the configuration for the client using the given string
 func loadClientConfiguration(cfgFile string) CLIENT_CONFIG {
 	log.Printf("Loading configuration from %s.", cfgFile)
 	_, err := toml.DecodeFile(cfgFile, &clientConfig)
-	switch clientConfig.PORT {
-	case 0:
-		clientConfig.SERVER_URL = clientConfig.SERVER
-	default:
-		clientConfig.SERVER_URL = "http://" + clientConfig.SERVER + ":" + strconv.Itoa(clientConfig.PORT)
-	}
 	if err != nil {
 		log.Fatalf("Could not read configuration file: %+v\n", err.Error())
 		os.Exit(EXIT_CODE.FILE_IO_ERROR)
 	}
+	protocol := "http://"
+	if clientConfig.USE_HTTPS {
+		protocol = "https://"
+	}
+	clientConfig.SERVER_URL = protocol + clientConfig.SERVER + ":" + strconv.Itoa(clientConfig.PORT)
 	return clientConfig
 }
 
@@ -85,12 +85,6 @@ func ExecuteClient() {
 	clientConfig.SERVER = "127.0.0.1"
 	clientConfig.PORT = 80
 	clientConfig.USE_HTTPS = false
-	switch clientConfig.PORT {
-	case 0:
-		clientConfig.SERVER_URL = clientConfig.SERVER
-	default:
-		clientConfig.SERVER_URL = "http://" + clientConfig.SERVER + ":" + strconv.Itoa(clientConfig.PORT)
-	}
 	filePath := flag.String("file", "", "defines a path to the configuration file")
 	flag.Parse()
 	if strings.Compare(*filePath, "") != 0 {