summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile7
-rw-r--r--args.go21
-rw-r--r--main.go10
3 files changed, 37 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index bfdc706..7e1c2bc 100644
--- a/Makefile
+++ b/Makefile
@@ -2,9 +2,14 @@ all:
-git pull
echo "build it!"
GO111MODULE=off go build -v -x
- ./powerpaneld
+ ./powerpaneld --hostname=breen
# su -c "setcap 'cap_net_bind_service=+ep' go.wit.com"
+run:
+ GO111MODULE=off go build -v -x
+ -systemctl stop powerpaneld.service
+ ./powerpaneld
+
goimports:
goimports -w *.go
diff --git a/args.go b/args.go
new file mode 100644
index 0000000..0b858ac
--- /dev/null
+++ b/args.go
@@ -0,0 +1,21 @@
+package main
+
+/*
+ this parses the command line arguements
+
+ this enables command line options from other packages like 'gui' and 'log'
+*/
+
+import (
+ "go.wit.com/dev/alexflint/arg"
+)
+
+var args struct {
+ ListRepos bool `arg:"--list-repos" help:"list all repositories"`
+ Port int `arg:"--port" help:"port to run on (default is 2520)"`
+ Hostname string `arg:"--hostname" help:"hostname to use"`
+}
+
+func init() {
+ arg.MustParse(&args)
+}
diff --git a/main.go b/main.go
index 61487a3..02e3144 100644
--- a/main.go
+++ b/main.go
@@ -45,6 +45,16 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
}
func main() {
+ var hostname string = args.Hostname
+
+ if hostname == "" {
+ hostname = "localhost"
+ }
+
+ log.Info("curl http://" + hostname + ":3000/powersource # shows if your power grid is up")
+ log.Info("curl http://" + hostname + ":3000/lastoutage # shows the last time your power grid went down")
+ log.Info("hostname =", hostname)
+
http.HandleFunc("/", okHandler)
err := http.ListenAndServe(":3000", nil)
if err != nil {