Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-08 13:19:14 -05:00
parent cc534d83da
commit 0e3fc9cb80
3 changed files with 37 additions and 1 deletions

View File

@ -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

21
args.go Normal file
View File

@ -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)
}

10
main.go
View File

@ -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 {