From 0e3fc9cb80f80f62aa737b659182e75588411c85 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 8 Oct 2024 13:19:14 -0500 Subject: [PATCH] add args Signed-off-by: Jeff Carr --- Makefile | 7 ++++++- args.go | 21 +++++++++++++++++++++ main.go | 10 ++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 args.go 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 {