summaryrefslogtreecommitdiff
path: root/src/main.go
diff options
context:
space:
mode:
authorxengineering <mail2xengineering@protonmail.com>2021-06-13 09:46:24 +0200
committerxengineering <mail2xengineering@protonmail.com>2021-06-13 09:46:24 +0200
commitc015034ba2e0bfd8464ae444792552a4b354eb0d (patch)
treeb22dd83105ef795974b62b74917084d07c636280 /src/main.go
parent6df5b35600e6aae6e676e2ba29eeaaf88bf9ff9b (diff)
downloadbirdscan-c015034ba2e0bfd8464ae444792552a4b354eb0d.tar
birdscan-c015034ba2e0bfd8464ae444792552a4b354eb0d.tar.zst
birdscan-c015034ba2e0bfd8464ae444792552a4b354eb0d.zip
Offer debug Make Target
Diffstat (limited to 'src/main.go')
-rw-r--r--src/main.go27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/main.go b/src/main.go
index d64533e..dfcf706 100644
--- a/src/main.go
+++ b/src/main.go
@@ -3,6 +3,7 @@
package main
import (
+ "flag"
"log"
"time"
"os"
@@ -10,46 +11,50 @@ import (
"encoding/json"
)
-const (
- CONFIG_FILE = "/etc/birdscan/config.json"
-)
-
type config struct {
WebConfig webConfig `json:"webserver"`
}
func main() {
+ configPath := readFlags()
log.SetFlags(0) // disable timestamp because systemd takes care of that
log.Println("Starting birdscan")
- cfg := readConfig()
+ cfg := readConfig(configPath)
go runServer(&cfg.WebConfig)
for {
time.Sleep(1 * time.Second)
}
}
-func readConfig() config {
+func readFlags() string {
+ var retval string
+ flag.StringVar(&retval, "c", "/etc/birdscan/config.json", "Path to birdscan configuration file")
+ flag.Parse()
+ return retval
+}
+
+func readConfig(path string) config {
- log.Printf("Reading config file %s", CONFIG_FILE)
+ log.Printf("Reading config file %s", path)
var retval config
// open the config file
- configFile, err := os.Open(CONFIG_FILE)
+ configFile, err := os.Open(path)
defer configFile.Close()
if err != nil {
- log.Fatalf("Could not open configuration file %s", CONFIG_FILE)
+ log.Fatalf("Could not open configuration file %s", path)
}
// read byte content
byteData, err := ioutil.ReadAll(configFile)
if err != nil {
- log.Fatalf("Could not read configuration file %s", CONFIG_FILE)
+ log.Fatalf("Could not read configuration file %s", path)
}
// parse content to config structs
err = json.Unmarshal(byteData, &retval)
if err != nil {
- log.Fatalf("Could not parse configuration file %s", CONFIG_FILE)
+ log.Fatalf("Could not parse configuration file %s", path)
}
return retval