Commit f1ec58c

Richard Luby <richluby@gmail.com>
2016-10-06 09:34:02
initial commit of main file
program allows default configuration or configuration file to be specified in code
Changed files (1)
questioner.go
@@ -0,0 +1,48 @@
+// this package implements a server-based question and answer system
+package main
+
+import (
+	"fmt"
+	"github.com/BurntSushi/toml"
+	"io/ioutil"
+)
+
+// define defaults for the server
+type CONFIG struct {
+	LISTEN_PORT, MAX_CONNECTIONS int
+	PERMIT_BLANK_PASSWORD        bool
+	PRIVATE_KEY                  string
+}
+
+var config CONFIG
+
+const defaultConfig = `
+LISTEN_PORT = 8022
+MAX_CONNECTIONS = 1500
+PERMIT_BLANK_PASSWORD = true
+PRIVATE_KEY = "~/.ssh/question.priv"
+`
+
+//LoadConfiguration loads the configuration file
+func LoadConfiguration(cfgFile string) CONFIG {
+	var contents string
+	if cfgFile == "" {
+		contents = defaultConfig
+	} else {
+		buffer, err := ioutil.ReadFile(cfgFile)
+		if err != nil {
+			panic(fmt.Sprintf("%+v", err))
+		}
+		contents = string(buffer)
+	}
+	if _, err := toml.Decode(contents, &config); err != nil {
+		panic(fmt.Sprintf("%+v", err))
+	}
+	return config
+}
+
+// main handles starting the listening server
+func main() {
+	LoadConfiguration("")
+	fmt.Printf("%+v\n", config)
+}