summaryrefslogtreecommitdiff
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
parent6df5b35600e6aae6e676e2ba29eeaaf88bf9ff9b (diff)
downloadbirdscan-c015034ba2e0bfd8464ae444792552a4b354eb0d.tar
birdscan-c015034ba2e0bfd8464ae444792552a4b354eb0d.tar.zst
birdscan-c015034ba2e0bfd8464ae444792552a4b354eb0d.zip
Offer debug Make Target
-rw-r--r--Makefile5
-rw-r--r--src/Makefile7
-rw-r--r--src/main.go27
3 files changed, 25 insertions, 14 deletions
diff --git a/Makefile b/Makefile
index 7e3e517..48af7e6 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@
DESTDIR="" # leave empty for the current system or provide a fakeroot here
PREFIX="/usr"
-.PHONY: all clean install
+.PHONY: all clean install debug
all:
make -C python all
@@ -23,3 +23,6 @@ install: all
install -Dm 644 data/css/birdscan.css $(DESTDIR)$(PREFIX)/share/birdscan/css/birdscan.css
install -Dm 644 data/js/birdscan.js $(DESTDIR)$(PREFIX)/share/birdscan/js/birdscan.js
+debug: all
+ make -C src debug
+
diff --git a/src/Makefile b/src/Makefile
index 02e9e39..3cb219f 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -3,7 +3,7 @@
DESTDIR="" # leave empty for the current system or provide a fakeroot here
PREFIX="/usr"
-.PHONY: all clean install
+.PHONY: all clean install debug
all:
# some recommended options for Go building (https://wiki.archlinux.org/title/Go_package_guidelines)
@@ -20,5 +20,8 @@ clean:
rm -rf build
install: all
- install -Dm 755 build/birdscan $(DESTDIR)$(PREFIX)/bin/birdscan
+ install -Dm 755 build/birdscan $(DESTDIR)$(PREFIX)/bin/birdscan
+
+debug: all
+ go run ./... -c ../config/default.json
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