aboutsummaryrefslogtreecommitdiff
path: root/cmd/whoisfront/main.go
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2020-01-31 14:57:43 +0000
committerChristine Dodrill <me@christine.website>2020-01-31 14:57:43 +0000
commitb9da6dacddf55e4ea3eb9e95de4bb04b17243314 (patch)
tree2a61235e9406860628e6fbc768cf559654572f88 /cmd/whoisfront/main.go
parentaad3bc95497e7ebf2dc69d21d5d53dc769345a88 (diff)
downloadx-b9da6dacddf55e4ea3eb9e95de4bb04b17243314.tar.xz
x-b9da6dacddf55e4ea3eb9e95de4bb04b17243314.zip
whoisfront: use mi only
Diffstat (limited to 'cmd/whoisfront/main.go')
-rw-r--r--cmd/whoisfront/main.go35
1 files changed, 10 insertions, 25 deletions
diff --git a/cmd/whoisfront/main.go b/cmd/whoisfront/main.go
index 9139af0..132ecf0 100644
--- a/cmd/whoisfront/main.go
+++ b/cmd/whoisfront/main.go
@@ -3,30 +3,24 @@ package main
import (
"bytes"
- "encoding/json"
"flag"
"fmt"
+ "io"
"io/ioutil"
"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")
- miToken = flag.String("mi-token", "", "Mi token")
-
- sc switchcounter.API
+ miToken = flag.String("mi-token", "", "Mi token")
)
func main() {
internal.HandleStartup()
- sc = switchcounter.NewHTTPClient(*switchCounterURL)
-
err := cgi.Serve(http.HandlerFunc(handle))
if err != nil {
log.Fatal(err)
@@ -57,15 +51,6 @@ func handle(w http.ResponseWriter, r *http.Request) {
panic(err)
}
defer r.Body.Close()
- req := sc.Switch(string(front))
- resp, err := http.DefaultClient.Do(req)
- if err != nil {
- panic(err)
- }
- err = switchcounter.Validate(resp)
- if err != nil {
- panic(err)
- }
err = miSwitch(string(front))
if err != nil {
@@ -77,21 +62,21 @@ func handle(w http.ResponseWriter, r *http.Request) {
return
}
- req := sc.Status()
- resp, err := http.DefaultClient.Do(req)
+ req, err := http.NewRequest(http.MethodGet, "https://mi.within.website/switches/current", nil)
if err != nil {
panic(err)
}
- err = switchcounter.Validate(resp)
+ req.Header.Add("Authorization", *miToken)
+ req.Header.Add("Accept", "text/plain")
+ resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
- var st switchcounter.Status
- err = json.NewDecoder(resp.Body).Decode(&st)
- if err != nil {
- panic(err)
+
+ if resp.StatusCode != http.StatusOK {
+ log.Panicf("bad status code: %d", resp.StatusCode)
}
w.Header().Set("Content-Type", "text/plain")
- fmt.Fprint(w, st.Front)
+ io.Copy(w, resp.Body)
}