diff options
| -rw-r--r-- | config.go | 7 | ||||
| -rw-r--r-- | main.go | 8 | 
2 files changed, 7 insertions, 8 deletions
@@ -7,6 +7,8 @@ import (  	"log"  ) +var config RuntimeConfig +  type RuntimeConfig struct {  	Devices DevicesConfig  	Web     WebConfig @@ -22,7 +24,7 @@ type WebConfig struct {  // parseConfig() parses and validates the runtime configuration file and  // returns it as Go datastructure. -func parseConfig(path string) RuntimeConfig { +func parseConfig(path string) {  	data, err := os.ReadFile(path)  	if err != nil {  		log.Fatalf("Could not read '%s'!", path) @@ -32,11 +34,8 @@ func parseConfig(path string) RuntimeConfig {  		log.Fatalf("%s contains invalid JSON!", path)  	} -	config := RuntimeConfig{}  	err = json.Unmarshal(data, &config)  	if err != nil {  		log.Fatalf("Could not parse configuration file:\n%s\n", err)  	} - -	return config  } @@ -15,7 +15,7 @@ var templates *template.Template  func main() {  	configPath := parseFlags() -	c := parseConfig(configPath) +	parseConfig(configPath)  	var err error  	templates, err = template.ParseFS(static, "templates/index.html") @@ -23,14 +23,14 @@ func main() {  		log.Fatal(err)  	} -	http.HandleFunc("/", index(c.Devices)) +	http.HandleFunc("/", index(config.Devices))  	http.HandleFunc("/api", api)  	http.Handle("/static/", http.StripPrefix("/static/",  		http.FileServer(http.FS(static)))) -	fmt.Printf("Serving at http://%s\n", c.Web.Listen) +	fmt.Printf("Serving at http://%s\n", config.Web.Listen) -	log.Fatal(http.ListenAndServe(c.Web.Listen.String(), nil)) +	log.Fatal(http.ListenAndServe(config.Web.Listen.String(), nil))  }  // parseFlags() handles command line interface (CLI) flags.  | 
