From 5965da82d217d5247d17064c0dc4e5ef4a0dbe16 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sat, 21 Sep 2019 20:58:15 +0000 Subject: set front too --- cmd/whoisfront/main.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'cmd') diff --git a/cmd/whoisfront/main.go b/cmd/whoisfront/main.go index ce3aff7..1ae9f51 100644 --- a/cmd/whoisfront/main.go +++ b/cmd/whoisfront/main.go @@ -5,6 +5,7 @@ import ( "encoding/json" "flag" "fmt" + "io/ioutil" "log" "net/http" "net/http/cgi" @@ -31,6 +32,26 @@ func main() { } func handle(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodPost { + front, err := ioutil.ReadAll(r.Body) + if err != nil { + 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) + } + w.Header().Set("Content-Type", "text/plain") + fmt.Fprint(w, string(front)) + return + } + req := sc.Status() resp, err := http.DefaultClient.Do(req) if err != nil { -- cgit v1.2.3