diff options
| author | Christine Dodrill <me@christine.website> | 2020-01-12 02:49:55 +0000 |
|---|---|---|
| committer | Christine Dodrill <me@christine.website> | 2020-01-12 02:50:06 +0000 |
| commit | aad3bc95497e7ebf2dc69d21d5d53dc769345a88 (patch) | |
| tree | 50ad6280fcc42df689944c2751be42d5add21496 /cmd/whoisfront/main.go | |
| parent | 98daf7a7b1145b7f750777497a4c9708f2225d28 (diff) | |
| download | x-aad3bc95497e7ebf2dc69d21d5d53dc769345a88.tar.xz x-aad3bc95497e7ebf2dc69d21d5d53dc769345a88.zip | |
cmd/whoisfront: push switches to Miv1.2.3
Diffstat (limited to 'cmd/whoisfront/main.go')
| -rw-r--r-- | cmd/whoisfront/main.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/cmd/whoisfront/main.go b/cmd/whoisfront/main.go index 1ae9f51..9139af0 100644 --- a/cmd/whoisfront/main.go +++ b/cmd/whoisfront/main.go @@ -2,6 +2,7 @@ package main import ( + "bytes" "encoding/json" "flag" "fmt" @@ -16,6 +17,7 @@ import ( var ( switchCounterURL = flag.String("switch-counter-url", "", "the webhook for switchcounter.science") + miToken = flag.String("mi-token", "", "Mi token") sc switchcounter.API ) @@ -31,6 +33,23 @@ func main() { } } +func miSwitch(to string) error { + req, err := http.NewRequest(http.MethodGet, "https://mi.within.website/switches/switch", bytes.NewBuffer([]byte(to))) + if err != nil { + return err + } + req.Header.Add("Authorization", *miToken) + + resp, err := http.DefaultClient.Do(req) + if err != nil { + return err + } + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("wanted %d, got: %s", http.StatusOK, resp.Status) + } + return nil +} + func handle(w http.ResponseWriter, r *http.Request) { if r.Method == http.MethodPost { front, err := ioutil.ReadAll(r.Body) @@ -47,6 +66,12 @@ func handle(w http.ResponseWriter, r *http.Request) { if err != nil { panic(err) } + + err = miSwitch(string(front)) + if err != nil { + panic(err) + } + w.Header().Set("Content-Type", "text/plain") fmt.Fprint(w, string(front)) return |
