diff options
| author | Christine Dodrill <me@christine.website> | 2019-06-13 22:32:04 +0000 |
|---|---|---|
| committer | Christine Dodrill <me@christine.website> | 2019-06-13 22:32:04 +0000 |
| commit | 6de9c7ba1efe9035edf23202cf2663ff06e41722 (patch) | |
| tree | 0c43b1b3b0c6f12c0b7aeb279ff35587e01db200 | |
| parent | 31f19d64ff1aa39d3e9c04d8a7e3a7f685a05451 (diff) | |
| download | x-6de9c7ba1efe9035edf23202cf2663ff06e41722.tar.xz x-6de9c7ba1efe9035edf23202cf2663ff06e41722.zip | |
cmd: add whoisfront CGI script for some automation
| -rw-r--r-- | cmd/whoisfront/main.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/cmd/whoisfront/main.go b/cmd/whoisfront/main.go new file mode 100644 index 0000000..13901d1 --- /dev/null +++ b/cmd/whoisfront/main.go @@ -0,0 +1,49 @@ +package main + +import ( + "encoding/json" + "flag" + "fmt" + "log" + "net/http" + "net/http/cgi" + + "within.website/x/internal" + "within.website/x/web/switchcounter" +) + +var ( + switchCounterURL = flag.String("switch-counter-url", "", "the webhook for switchcounter.science") + + sc switchcounter.API +) + +func main() { + internal.HandleStartup() + + sc = switchcounter.NewHTTPClient(*switchCounterURL) + + err := cgi.Serve(http.HandlerFunc(handle)) + if err != nil { + log.Fatal(err) + } +} + +func handle(w http.ResponseWriter, r *http.Request) { + req := sc.Status() + resp, err := http.DefaultClient.Do(req) + if err != nil { + panic(err) + } + err = switchcounter.Validate(resp) + if err != nil { + panic(err) + } + var st switchcounter.Status + err = json.NewDecoder(resp.Body).Decode(&st) + if err != nil { + panic(err) + } + + fmt.Fprintln(w, st.Front) +} |
