diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 37 |
1 files changed, 0 insertions, 37 deletions
@@ -1,33 +1,17 @@ package main import ( - "encoding/json" "embed" "flag" "fmt" "log" "net/http" - "net/netip" - "os" "text/template" ) //go:embed simple.css/simple.css templates/index.html var static embed.FS -type RuntimeConfig struct { - Devices DevicesConfig - Web WebConfig -} - -type DevicesConfig struct { - Hs100 []Hs100Conf -} - -type WebConfig struct { - Listen netip.AddrPort -} - func main() { configPath := parseFlags() c := parseConfig(configPath) @@ -51,27 +35,6 @@ func parseFlags() string { return r } -// parseConfig() parses and validates the runtime configuration file and -// returns it as Go datastructure. -func parseConfig(path string) RuntimeConfig { - data, err := os.ReadFile(path) - if err != nil { - log.Fatalf("Could not read '%s'!", path) - } - - if !json.Valid(data) { - 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 -} - // index() returns a HTTP handler for the index page. func index(devices DevicesConfig) func(http.ResponseWriter, *http.Request) { tmpl, err := template.ParseFS(static, "templates/index.html") |