summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go9
1 files changed, 1 insertions, 8 deletions
diff --git a/main.go b/main.go
index 637f7d1..a99b46b 100644
--- a/main.go
+++ b/main.go
@@ -28,7 +28,6 @@ type WebConfig struct {
Listen netip.AddrPort
}
-// main() contains the control flow of this program.
func main() {
configPath := parseFlags()
c := parseConfig(configPath)
@@ -42,7 +41,7 @@ func main() {
// parseFlags() handles command line interface (CLI) flags.
func parseFlags() string {
- var r string // return value
+ var r string
flag.StringVar(&r, "c", "/etc/webiot/config.json",
"path to configuration file")
@@ -57,13 +56,11 @@ func parseFlags() string {
// returns it as Go datastructure.
func parseConfig(path string) RuntimeConfig {
- // read config file and ensure proper JSON formatting
data := mustRead(path)
if !json.Valid(data) {
log.Fatalf("%s contains invalid JSON!", path)
}
- // read to RuntimeConfig struct and handle errors
config := RuntimeConfig{}
err := json.Unmarshal(data, &config)
if err != nil {
@@ -76,7 +73,6 @@ func parseConfig(path string) RuntimeConfig {
// index() returns a HTTP handler for the index page.
func index(devices DevicesConfig, appdata string) func(http.ResponseWriter, *http.Request) {
- // prepare HTML
path := filepath.Join(appdata, "index.html.tmpl")
html := mustRender(path, devices)
@@ -87,7 +83,6 @@ func index(devices DevicesConfig, appdata string) func(http.ResponseWriter, *htt
func css(appdata string) func(http.ResponseWriter, *http.Request) {
- // read CSS file
path := filepath.Join(appdata, "simple.css")
css := string(mustRead(path))
@@ -128,7 +123,6 @@ func api() func(http.ResponseWriter, *http.Request) {
// TODO assert correct HTTP method
- // read parameters and handle errors
errHost, host := assertSingleParam(r, "host")
errState, state := assertSingleParam(r, "state")
if (errHost != nil) || (errState != nil) {
@@ -137,7 +131,6 @@ func api() func(http.ResponseWriter, *http.Request) {
return
}
- // set WiFi plug
err := set(host, state)
if err != nil {
http.Error(w, "Could not set WiFi plug.", 500)